axum_core/ext_traits/
mod.rs
1pub(crate) mod request;
2pub(crate) mod request_parts;
3
4#[cfg(test)]
5mod tests {
6 use std::convert::Infallible;
7
8 use crate::extract::{FromRef, FromRequestParts};
9 use http::request::Parts;
10
11 #[derive(Debug, Default, Clone, Copy)]
12 pub(crate) struct State<S>(pub(crate) S);
13
14 impl<OuterState, InnerState> FromRequestParts<OuterState> for State<InnerState>
15 where
16 InnerState: FromRef<OuterState>,
17 OuterState: Send + Sync,
18 {
19 type Rejection = Infallible;
20
21 async fn from_request_parts(
22 _parts: &mut Parts,
23 state: &OuterState,
24 ) -> Result<Self, Self::Rejection> {
25 let inner_state = InnerState::from_ref(state);
26 Ok(Self(inner_state))
27 }
28 }
29
30 #[allow(dead_code)]
32 pub(crate) struct RequiresState(pub(crate) String);
33
34 impl<S> FromRequestParts<S> for RequiresState
35 where
36 S: Send + Sync,
37 String: FromRef<S>,
38 {
39 type Rejection = Infallible;
40
41 async fn from_request_parts(
42 _parts: &mut Parts,
43 state: &S,
44 ) -> Result<Self, Self::Rejection> {
45 Ok(Self(String::from_ref(state)))
46 }
47 }
48}