mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-03 17:52:18 +01:00
Remove CloneBoxService
(#542)
Its been [upstreamed to tower](https://github.com/tower-rs/tower/pull/615).
This commit is contained in:
parent
f9a437d081
commit
badbb14cce
4 changed files with 10 additions and 77 deletions
|
@ -35,7 +35,7 @@ serde_urlencoded = "0.7"
|
||||||
sync_wrapper = "0.1.1"
|
sync_wrapper = "0.1.1"
|
||||||
tokio = { version = "1", features = ["time"] }
|
tokio = { version = "1", features = ["time"] }
|
||||||
tokio-util = "0.6"
|
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-http = { version = "0.1", features = ["add-extension", "map-response-body"] }
|
||||||
tower-layer = "0.3"
|
tower-layer = "0.3"
|
||||||
tower-service = "0.3"
|
tower-service = "0.3"
|
||||||
|
|
|
@ -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<T, U, E>(
|
|
||||||
Box<
|
|
||||||
dyn CloneService<T, Response = U, Error = E, Future = BoxFuture<'static, Result<U, E>>>
|
|
||||||
+ Send,
|
|
||||||
>,
|
|
||||||
);
|
|
||||||
|
|
||||||
impl<T, U, E> CloneBoxService<T, U, E> {
|
|
||||||
pub(crate) fn new<S>(inner: S) -> Self
|
|
||||||
where
|
|
||||||
S: Service<T, Response = U, Error = E> + Clone + Send + 'static,
|
|
||||||
S::Future: Send + 'static,
|
|
||||||
{
|
|
||||||
let inner = inner.map_future(|f| Box::pin(f) as _);
|
|
||||||
CloneBoxService(Box::new(inner))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, U, E> Service<T> for CloneBoxService<T, U, E> {
|
|
||||||
type Response = U;
|
|
||||||
type Error = E;
|
|
||||||
type Future = BoxFuture<'static, Result<U, E>>;
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), E>> {
|
|
||||||
self.0.poll_ready(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
fn call(&mut self, request: T) -> Self::Future {
|
|
||||||
self.0.call(request)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T, U, E> Clone for CloneBoxService<T, U, E> {
|
|
||||||
fn clone(&self) -> Self {
|
|
||||||
Self(self.0.clone_box())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
trait CloneService<R>: Service<R> {
|
|
||||||
fn clone_box(
|
|
||||||
&self,
|
|
||||||
) -> Box<
|
|
||||||
dyn CloneService<R, Response = Self::Response, Error = Self::Error, Future = Self::Future>
|
|
||||||
+ Send,
|
|
||||||
>;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<R, T> CloneService<R> for T
|
|
||||||
where
|
|
||||||
T: Service<R> + Send + Clone + 'static,
|
|
||||||
{
|
|
||||||
fn clone_box(
|
|
||||||
&self,
|
|
||||||
) -> Box<dyn CloneService<R, Response = T::Response, Error = T::Error, Future = T::Future> + Send>
|
|
||||||
{
|
|
||||||
Box::new(self.clone())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -376,7 +376,6 @@
|
||||||
pub(crate) mod macros;
|
pub(crate) mod macros;
|
||||||
|
|
||||||
mod add_extension;
|
mod add_extension;
|
||||||
mod clone_box_service;
|
|
||||||
mod error;
|
mod error;
|
||||||
#[cfg(feature = "json")]
|
#[cfg(feature = "json")]
|
||||||
mod json;
|
mod json;
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
use crate::{
|
use crate::body::{boxed, Body, BoxBody};
|
||||||
body::{boxed, Body, BoxBody},
|
|
||||||
clone_box_service::CloneBoxService,
|
|
||||||
};
|
|
||||||
use http::{Request, Response};
|
use http::{Request, Response};
|
||||||
use http_body::Empty;
|
use http_body::Empty;
|
||||||
use pin_project_lite::pin_project;
|
use pin_project_lite::pin_project;
|
||||||
|
@ -12,7 +9,10 @@ use std::{
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
use tower::{util::Oneshot, ServiceExt};
|
use tower::{
|
||||||
|
util::{BoxCloneService, Oneshot},
|
||||||
|
ServiceExt,
|
||||||
|
};
|
||||||
use tower_service::Service;
|
use tower_service::Service;
|
||||||
|
|
||||||
/// How routes are stored inside a [`Router`](super::Router).
|
/// 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
|
/// You normally shouldn't need to care about this type. It's used in
|
||||||
/// [`Router::layer`](super::Router::layer).
|
/// [`Router::layer`](super::Router::layer).
|
||||||
pub struct Route<B = Body, E = Infallible>(
|
pub struct Route<B = Body, E = Infallible>(
|
||||||
pub(crate) CloneBoxService<Request<B>, Response<BoxBody>, E>,
|
pub(crate) BoxCloneService<Request<B>, Response<BoxBody>, E>,
|
||||||
);
|
);
|
||||||
|
|
||||||
impl<B, E> Route<B, E> {
|
impl<B, E> Route<B, E> {
|
||||||
|
@ -29,7 +29,7 @@ impl<B, E> Route<B, E> {
|
||||||
T: Service<Request<B>, Response = Response<BoxBody>, Error = E> + Clone + Send + 'static,
|
T: Service<Request<B>, Response = Response<BoxBody>, Error = E> + Clone + Send + 'static,
|
||||||
T::Future: Send + 'static,
|
T::Future: Send + 'static,
|
||||||
{
|
{
|
||||||
Self(CloneBoxService::new(svc))
|
Self(BoxCloneService::new(svc))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ pin_project! {
|
||||||
pub struct RouteFuture<B, E> {
|
pub struct RouteFuture<B, E> {
|
||||||
#[pin]
|
#[pin]
|
||||||
future: Oneshot<
|
future: Oneshot<
|
||||||
CloneBoxService<Request<B>, Response<BoxBody>, E>,
|
BoxCloneService<Request<B>, Response<BoxBody>, E>,
|
||||||
Request<B>,
|
Request<B>,
|
||||||
>,
|
>,
|
||||||
strip_body: bool,
|
strip_body: bool,
|
||||||
|
@ -75,7 +75,7 @@ pin_project! {
|
||||||
|
|
||||||
impl<B, E> RouteFuture<B, E> {
|
impl<B, E> RouteFuture<B, E> {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
future: Oneshot<CloneBoxService<Request<B>, Response<BoxBody>, E>, Request<B>>,
|
future: Oneshot<BoxCloneService<Request<B>, Response<BoxBody>, E>, Request<B>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
RouteFuture {
|
RouteFuture {
|
||||||
future,
|
future,
|
||||||
|
|
Loading…
Reference in a new issue