chuanyue-service/library/src/extractor/context_extractor.rs
2024-10-01 17:24:40 +08:00

18 lines
443 B
Rust

use axum::{async_trait, extract::FromRequestParts};
use http::request::Parts;
use crate::{context::Context, model::response::ResErr};
#[async_trait]
impl<S> FromRequestParts<S> for Context
where
S: Send + Sync,
{
type Rejection = ResErr;
async fn from_request_parts(parts: &mut Parts, _: &S) -> Result<Self, Self::Rejection> {
let context: &Context = parts.extensions.get().unwrap();
Ok(context.clone())
}
}