use axum::extract::{FromRequestParts, FromRef}; use axum::http::request::Parts as RequestParts; use core::convert::Infallible; use std::future::Future; /// An extractor that extracts the state of the application. #[repr(transparent)] #[derive(Debug, Default, Clone, Copy)] pub struct State(S); impl FromRequestParts for State where InnerState: FromRef, OuterState: Send + Sync, { type Rejection = Infallible; fn from_request_parts<'a: 'c, 'b: 'c, 'c>( _: &'a mut RequestParts, state: &'b OuterState, ) -> core::pin::Pin> + Send + 'c, >> where Self: 'c { Box::pin(async move { Ok(Self(InnerState::from_ref(state))) }) } } impl core::ops::Deref for State { type Target = S; #[inline] fn deref(&self) -> &Self::Target { &self.0 } } impl core::ops::DerefMut for State { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } }