shield_dioxus/
integration.rs

1use std::sync::Arc;
2
3use async_trait::async_trait;
4use shield::{Session, ShieldDyn};
5
6#[async_trait]
7pub trait DioxusIntegration: Send + Sync {
8    async fn extract_shield(&self) -> ShieldDyn;
9
10    async fn extract_session(&self) -> 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 async fn extract_shield(&self) -> ShieldDyn {
22        self.0.extract_shield().await
23    }
24
25    pub async fn extract_session(&self) -> Session {
26        self.0.extract_session().await
27    }
28}