diff --git a/axum/src/handler/into_service_state_in_extension.rs b/axum/src/handler/into_service_state_in_extension.rs deleted file mode 100644 index 61f7ed43..00000000 --- a/axum/src/handler/into_service_state_in_extension.rs +++ /dev/null @@ -1,84 +0,0 @@ -use super::Handler; -use crate::response::Response; -use http::Request; -use std::{ - convert::Infallible, - fmt, - marker::PhantomData, - task::{Context, Poll}, -}; -use tower_service::Service; - -pub(crate) struct IntoServiceStateInExtension { - handler: H, - _marker: PhantomData (T, S, B)>, -} - -#[test] -fn traits() { - use crate::test_helpers::*; - assert_send::>(); - assert_sync::>(); -} - -impl IntoServiceStateInExtension { - pub(crate) fn new(handler: H) -> Self { - Self { - handler, - _marker: PhantomData, - } - } -} - -impl fmt::Debug for IntoServiceStateInExtension { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.debug_struct("IntoServiceStateInExtension") - .finish_non_exhaustive() - } -} - -impl Clone for IntoServiceStateInExtension -where - H: Clone, -{ - fn clone(&self) -> Self { - Self { - handler: self.handler.clone(), - _marker: PhantomData, - } - } -} - -impl Service> for IntoServiceStateInExtension -where - H: Handler + Clone + Send + 'static, - B: Send + 'static, - S: Send + Sync + 'static, -{ - type Response = Response; - type Error = Infallible; - type Future = super::future::IntoServiceFuture; - - #[inline] - fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll> { - // `IntoServiceStateInExtension` can only be constructed from async functions which are always ready, or - // from `Layered` which buffers in `::call` and is therefore - // also always ready. - Poll::Ready(Ok(())) - } - - fn call(&mut self, mut req: Request) -> Self::Future { - use futures_util::future::FutureExt; - - let state = req - .extensions_mut() - .remove::() - .expect("state extension missing. This is a bug in axum, please file an issue"); - - let handler = self.handler.clone(); - let future = Handler::call(handler, req, state); - let future = future.map(Ok as _); - - super::future::IntoServiceFuture::new(future) - } -}