Skip to main content

anvil_core/
request.rs

1//! Request extras — re-exports and helpers around Axum extractors.
2
3pub use axum::extract::{Form, Json, Path, Query, State};
4pub use axum::http::{HeaderMap, Method, StatusCode, Uri};
5
6use axum::async_trait;
7use axum::extract::{FromRef, FromRequestParts};
8use axum::http::request::Parts;
9
10use crate::container::Container;
11use crate::Error;
12
13/// An extractor that yields the container reference, with `?`-friendly error.
14pub struct App(pub Container);
15
16#[async_trait]
17impl<S> FromRequestParts<S> for App
18where
19    Container: FromRef<S>,
20    S: Send + Sync,
21{
22    type Rejection = Error;
23
24    async fn from_request_parts(_parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
25        Ok(App(Container::from_ref(state)))
26    }
27}
28
29// The blanket `impl<T: Clone> FromRef<T> for T` in axum_core covers
30// `FromRef<Container> for Container` already; we don't need an explicit impl.