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
use {
    serde::{Deserialize, Serialize},
    std::fmt::{Display, Formatter, Result as FmtResult},
};

#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum Effect {
    Allow,
    Deny,
}

impl Display for Effect {
    fn fmt(&self, f: &mut Formatter) -> FmtResult {
        match self {
            Self::Allow => f.write_str("Allow"),
            Self::Deny => f.write_str("Deny"),
        }
    }
}

#[cfg(test)]
mod tests {
    use {crate::Effect, pretty_assertions::assert_eq, std::collections::HashMap};

    #[test_log::test]
    fn test_hash() {
        let mut hash_map = HashMap::new();
        hash_map.insert(Effect::Allow, 1);
        hash_map.insert(Effect::Deny, 2);

        assert_eq!(hash_map.get(&Effect::Allow), Some(&1));
        assert_eq!(hash_map.get(&Effect::Deny), Some(&2));
    }

    #[test_log::test]
    fn test_display() {
        assert_eq!(format!("{}", Effect::Allow), "Allow");
        assert_eq!(format!("{}", Effect::Deny), "Deny");
    }
}