atproto_oauth/axum/
state.rs1use axum::extract::{FromRef, FromRequestParts};
7use http::request::Parts;
8use std::{convert::Infallible, sync::Arc};
9
10use crate::storage::OAuthRequestStorage;
11
12#[derive(Clone)]
16pub struct OAuthRequestStorageExtractor(pub Arc<dyn OAuthRequestStorage + Send + Sync>);
17
18impl<S> FromRequestParts<S> for OAuthRequestStorageExtractor
19where
20 Arc<dyn OAuthRequestStorage + Send + Sync>: FromRef<S>,
21 S: Send + Sync,
22{
23 type Rejection = Infallible;
24
25 async fn from_request_parts(_parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
26 let storage = Arc::<dyn OAuthRequestStorage + Send + Sync>::from_ref(state);
27 Ok(OAuthRequestStorageExtractor(storage))
28 }
29}