#[derive(
Debug,
PartialEq,
Eq,
Copy,
Clone,
Hash,
PartialOrd,
Ord,
strum::Display,
strum::AsRefStr,
strum::EnumString,
serde_with::SerializeDisplay,
serde_with::DeserializeFromStr,
)]
#[strum(serialize_all = "SCREAMING-KEBAB-CASE")]
pub enum Mechanism {
Plain,
Login,
CramMd5,
Anonymous,
}
impl Mechanism {
#[inline]
#[must_use]
pub const fn client_first(self) -> bool {
match self {
Self::Plain | Self::Anonymous => true,
Self::Login | Self::CramMd5 => false,
}
}
#[inline]
#[must_use]
pub const fn must_be_under_tls(self) -> bool {
match self {
Self::Plain | Self::Login | Self::CramMd5 | Self::Anonymous => true,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn to_str() {
assert_eq!(Mechanism::Plain.to_string(), "PLAIN");
assert_eq!(Mechanism::Login.to_string(), "LOGIN");
assert_eq!(Mechanism::CramMd5.to_string(), "CRAM-MD5");
assert_eq!(Mechanism::Anonymous.to_string(), "ANONYMOUS");
}
#[test]
fn error() {
<Mechanism as std::str::FromStr>::from_str("foobar").unwrap_err();
}
}