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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#[derive(PartialEq, Debug, Clone)] pub enum Authentication { Password { username: String, password: String }, None, } impl Authentication { pub fn id(&self) -> u8 { match self { Authentication::Password { .. } => 2, Authentication::None => 0, } } pub fn is_no_auth(&self) -> bool { Authentication::None == *self } } mod to_auth; pub use to_auth::ToAuthentication; #[cfg(test)] mod tests { use super::*; #[test] fn auth_eq() { assert_eq!( Authentication::Password { username: "usr".to_string(), password: "pwd".to_string(), }, Authentication::Password { username: "usr".to_string(), password: "pwd".to_string(), }, ); assert_eq!(Authentication::None, Authentication::None); } #[test] fn auth_id() { assert_eq!( Authentication::Password { username: "usr".to_string(), password: "pwd".to_string(), } .id(), 2, ); assert_eq!(Authentication::None.id(), 0); } #[test] fn no_auth() { assert!(Authentication::None.is_no_auth()); assert!(!Authentication::Password { username: "usr".to_string(), password: "pwd".to_string(), } .is_no_auth()); } }