casbin/model/
mod.rs

1use crate::{rbac::RoleManager, Result};
2
3#[cfg(feature = "incremental")]
4use crate::emitter::EventData;
5
6use parking_lot::RwLock;
7
8use std::{collections::HashMap, sync::Arc};
9
10mod assertion;
11mod default_model;
12pub mod function_map;
13
14pub use assertion::{Assertion, AssertionMap};
15pub use default_model::DefaultModel;
16pub use function_map::*;
17
18pub trait Model: Send + Sync {
19    fn add_def(&mut self, sec: &str, key: &str, value: &str) -> bool;
20    fn get_model(&self) -> &HashMap<String, AssertionMap>;
21    fn get_mut_model(&mut self) -> &mut HashMap<String, AssertionMap>;
22    fn build_role_links(
23        &mut self,
24        rm: Arc<RwLock<dyn RoleManager>>,
25    ) -> Result<()>;
26    #[cfg(feature = "incremental")]
27    fn build_incremental_role_links(
28        &mut self,
29        rm: Arc<RwLock<dyn RoleManager>>,
30        d: EventData,
31    ) -> Result<()>;
32    fn add_policy(&mut self, sec: &str, ptype: &str, rule: Vec<String>)
33        -> bool;
34    fn add_policies(
35        &mut self,
36        sec: &str,
37        ptype: &str,
38        rules: Vec<Vec<String>>,
39    ) -> bool;
40    fn get_policy(&self, sec: &str, ptype: &str) -> Vec<Vec<String>>;
41    fn get_filtered_policy(
42        &self,
43        sec: &str,
44        ptype: &str,
45        field_index: usize,
46        field_values: Vec<String>,
47    ) -> Vec<Vec<String>>;
48    fn has_policy(&self, sec: &str, ptype: &str, rule: Vec<String>) -> bool;
49    fn get_values_for_field_in_policy(
50        &self,
51        sec: &str,
52        ptype: &str,
53        field_index: usize,
54    ) -> Vec<String>;
55    fn remove_policy(
56        &mut self,
57        sec: &str,
58        ptype: &str,
59        rule: Vec<String>,
60    ) -> bool;
61    fn remove_policies(
62        &mut self,
63        sec: &str,
64        ptype: &str,
65        rules: Vec<Vec<String>>,
66    ) -> bool;
67    fn clear_policy(&mut self);
68    fn remove_filtered_policy(
69        &mut self,
70        sec: &str,
71        ptype: &str,
72        field_index: usize,
73        field_values: Vec<String>,
74    ) -> (bool, Vec<Vec<String>>);
75    fn to_text(&self) -> String;
76}