diff --git a/axum/Cargo.toml b/axum/Cargo.toml index e3ac7948..a5070a01 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -35,7 +35,7 @@ serde_urlencoded = "0.7" sync_wrapper = "0.1.1" tokio = { version = "1", features = ["time"] } tokio-util = "0.6" -tower = { version = "0.4.10", default-features = false, features = ["util", "buffer", "make"] } +tower = { version = "0.4.11", default-features = false, features = ["util", "buffer", "make"] } tower-http = { version = "0.1", features = ["add-extension", "map-response-body"] } tower-layer = "0.3" tower-service = "0.3" diff --git a/axum/src/clone_box_service.rs b/axum/src/clone_box_service.rs deleted file mode 100644 index e75c71dd..00000000 --- a/axum/src/clone_box_service.rs +++ /dev/null @@ -1,66 +0,0 @@ -use futures_util::future::BoxFuture; -use std::task::{Context, Poll}; -use tower::ServiceExt; -use tower_service::Service; - -/// A `Clone + Send` boxed `Service` -pub(crate) struct CloneBoxService( - Box< - dyn CloneService>> - + Send, - >, -); - -impl CloneBoxService { - pub(crate) fn new(inner: S) -> Self - where - S: Service + Clone + Send + 'static, - S::Future: Send + 'static, - { - let inner = inner.map_future(|f| Box::pin(f) as _); - CloneBoxService(Box::new(inner)) - } -} - -impl Service for CloneBoxService { - type Response = U; - type Error = E; - type Future = BoxFuture<'static, Result>; - - #[inline] - fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { - self.0.poll_ready(cx) - } - - #[inline] - fn call(&mut self, request: T) -> Self::Future { - self.0.call(request) - } -} - -impl Clone for CloneBoxService { - fn clone(&self) -> Self { - Self(self.0.clone_box()) - } -} - -trait CloneService: Service { - fn clone_box( - &self, - ) -> Box< - dyn CloneService - + Send, - >; -} - -impl CloneService for T -where - T: Service + Send + Clone + 'static, -{ - fn clone_box( - &self, - ) -> Box + Send> - { - Box::new(self.clone()) - } -} diff --git a/axum/src/lib.rs b/axum/src/lib.rs index d2060072..98f45025 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -376,7 +376,6 @@ pub(crate) mod macros; mod add_extension; -mod clone_box_service; mod error; #[cfg(feature = "json")] mod json; diff --git a/axum/src/routing/route.rs b/axum/src/routing/route.rs index 8ae00fd2..6a1b590c 100644 --- a/axum/src/routing/route.rs +++ b/axum/src/routing/route.rs @@ -1,7 +1,4 @@ -use crate::{ - body::{boxed, Body, BoxBody}, - clone_box_service::CloneBoxService, -}; +use crate::body::{boxed, Body, BoxBody}; use http::{Request, Response}; use http_body::Empty; use pin_project_lite::pin_project; @@ -12,7 +9,10 @@ use std::{ pin::Pin, task::{Context, Poll}, }; -use tower::{util::Oneshot, ServiceExt}; +use tower::{ + util::{BoxCloneService, Oneshot}, + ServiceExt, +}; use tower_service::Service; /// How routes are stored inside a [`Router`](super::Router). @@ -20,7 +20,7 @@ use tower_service::Service; /// You normally shouldn't need to care about this type. It's used in /// [`Router::layer`](super::Router::layer). pub struct Route( - pub(crate) CloneBoxService, Response, E>, + pub(crate) BoxCloneService, Response, E>, ); impl Route { @@ -29,7 +29,7 @@ impl Route { T: Service, Response = Response, Error = E> + Clone + Send + 'static, T::Future: Send + 'static, { - Self(CloneBoxService::new(svc)) + Self(BoxCloneService::new(svc)) } } @@ -66,7 +66,7 @@ pin_project! { pub struct RouteFuture { #[pin] future: Oneshot< - CloneBoxService, Response, E>, + BoxCloneService, Response, E>, Request, >, strip_body: bool, @@ -75,7 +75,7 @@ pin_project! { impl RouteFuture { pub(crate) fn new( - future: Oneshot, Response, E>, Request>, + future: Oneshot, Response, E>, Request>, ) -> Self { RouteFuture { future,