1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Credentials {
pub username: Option<String>,
pub password: Option<String>
}
impl Credentials {
pub fn new(username: &str, password: &str) -> Credentials {
Credentials {
username: Some(username.to_owned()),
password: Some(password.to_owned())
}
}
pub fn empty() -> Credentials {
Credentials {
username: None,
password: None
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_constructors() {
let credentials = Credentials::new("username", "password");
assert_eq!(credentials.username, Some("username".to_owned()));
assert_eq!(credentials.password, Some("password".to_owned()));
let credentials = Credentials::empty();
assert_eq!(credentials.username, None);
assert_eq!(credentials.password, None);
}
}