Skip to main content

anvil_core/
request.rs

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