scratchstack-aspen 0.3.1

AWS IAM policy language (Aspen) parser and internal representation
Documentation
use {
    serde::{Deserialize, Serialize},
    std::fmt::{Display, Formatter, Result as FmtResult},
};

/// Effect of an Aspen statement.
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub enum Effect {
    /// Allow the action.
    Allow,

    /// Deny the action.
    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");
    }
}