cloudillo_types/abac.rs
1//! Attribute-based access control trait.
2
3/// Attribute set trait - all objects implement this
4pub trait AttrSet: Send + Sync {
5 /// Get a single string attribute
6 fn get(&self, key: &str) -> Option<&str>;
7
8 /// Get a list attribute
9 fn get_list(&self, key: &str) -> Option<Vec<&str>>;
10
11 /// Check if attribute equals value
12 fn has(&self, key: &str, value: &str) -> bool {
13 self.get(key) == Some(value)
14 }
15
16 /// Check if list attribute contains value
17 fn contains(&self, key: &str, value: &str) -> bool {
18 self.get_list(key).map(|list| list.contains(&value)).unwrap_or(false)
19 }
20}
21
22// vim: ts=4