casbin/adapter/
mod.rs

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use async_trait::async_trait;

pub mod memory_adapter;
pub mod null_adapter;
pub mod string_adapter;

#[cfg(not(target_arch = "wasm32"))]
pub mod file_adapter;

pub use memory_adapter::MemoryAdapter;
pub use null_adapter::NullAdapter;
pub use string_adapter::StringAdapter;

#[cfg(not(target_arch = "wasm32"))]
pub use file_adapter::FileAdapter;

use crate::{model::Model, Result};

#[derive(Clone)]
pub struct Filter<'a> {
    pub p: Vec<&'a str>,
    pub g: Vec<&'a str>,
}

#[async_trait]
pub trait Adapter: Send + Sync {
    async fn load_policy(&mut self, m: &mut dyn Model) -> Result<()>;
    async fn load_filtered_policy<'a>(
        &mut self,
        m: &mut dyn Model,
        f: Filter<'a>,
    ) -> Result<()>;
    async fn save_policy(&mut self, m: &mut dyn Model) -> Result<()>;
    async fn clear_policy(&mut self) -> Result<()>;
    fn is_filtered(&self) -> bool;
    async fn add_policy(
        &mut self,
        sec: &str,
        ptype: &str,
        rule: Vec<String>,
    ) -> Result<bool>;
    async fn add_policies(
        &mut self,
        sec: &str,
        ptype: &str,
        rules: Vec<Vec<String>>,
    ) -> Result<bool>;
    async fn remove_policy(
        &mut self,
        sec: &str,
        ptype: &str,
        rule: Vec<String>,
    ) -> Result<bool>;
    async fn remove_policies(
        &mut self,
        sec: &str,
        ptype: &str,
        rules: Vec<Vec<String>>,
    ) -> Result<bool>;
    async fn remove_filtered_policy(
        &mut self,
        sec: &str,
        ptype: &str,
        field_index: usize,
        field_values: Vec<String>,
    ) -> Result<bool>;
}