Skip to main content

shield_dioxus/
integration.rs

1use std::sync::Arc;
2
3use anyhow::Result;
4use dioxus::fullstack::http::Extensions;
5use shield::{Session, ShieldDyn};
6
7pub trait DioxusIntegration: Send + Sync {
8    fn extract_shield(&self, extensions: &Extensions) -> Result<ShieldDyn>;
9
10    fn extract_session(&self, extensions: &Extensions) -> Result<Session>;
11}
12
13#[derive(Clone)]
14pub struct DioxusIntegrationDyn(Arc<dyn DioxusIntegration>);
15
16impl DioxusIntegrationDyn {
17    pub fn new<I: DioxusIntegration + 'static>(integration: I) -> Self {
18        Self(Arc::new(integration))
19    }
20
21    pub fn extract_shield(&self, extensions: &Extensions) -> Result<ShieldDyn> {
22        self.0.extract_shield(extensions)
23    }
24
25    pub fn extract_session(&self, extensions: &Extensions) -> Result<Session> {
26        self.0.extract_session(extensions)
27    }
28}