Skip to main content

shield_dummy/
method.rs

1use std::sync::Arc;
2
3use async_trait::async_trait;
4use shield::{Action, Method, ShieldError, Storage, User, erased_method};
5
6use crate::{
7    actions::{DummySignInAction, DummySignOutAction},
8    provider::DummyProvider,
9};
10
11pub const DUMMY_METHOD_ID: &str = "dummy";
12
13pub struct DummyMethod<U: User> {
14    storage: Arc<dyn Storage<U>>,
15}
16
17impl<U: User> DummyMethod<U> {
18    pub fn new<S: Storage<U> + 'static>(storage: S) -> Self {
19        Self {
20            storage: Arc::new(storage),
21        }
22    }
23}
24
25#[async_trait]
26impl<U: User + 'static> Method for DummyMethod<U> {
27    type Provider = DummyProvider;
28    type Session = ();
29
30    fn id(&self) -> String {
31        DUMMY_METHOD_ID.to_owned()
32    }
33
34    fn actions(&self) -> Vec<Box<dyn Action<Self::Provider, Self::Session>>> {
35        vec![
36            Box::new(DummySignInAction::new(self.storage.clone())),
37            Box::new(DummySignOutAction),
38        ]
39    }
40
41    async fn providers(&self) -> Result<Vec<Self::Provider>, ShieldError> {
42        Ok(vec![DummyProvider])
43    }
44}
45
46erased_method!(DummyMethod, <U: User>);