mirror of https://github.com/tokio-rs/axum
Remove `routing::Layered` (#383)
This commit is contained in:
parent
8ca5538405
commit
554e3a0ad4
|
@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- **breaking:** Added feature flags for HTTP1 and JSON. This enables removing a
|
||||
few dependencies if your app only uses HTTP2 or doesn't use JSON. Its only a
|
||||
breaking change if you depend on axum with `default_features = false`. ([#286])
|
||||
- **breaking:** Remove `routing::Layered` as it didn't actually do anything and
|
||||
thus wasn't necessary
|
||||
|
||||
[#339]: https://github.com/tokio-rs/axum/pull/339
|
||||
[#286]: https://github.com/tokio-rs/axum/pull/286
|
||||
|
|
|
@ -241,7 +241,7 @@ pub trait Handler<B, T>: Clone + Send + Sized + 'static {
|
|||
/// This can be used to add additional processing to a request for a single
|
||||
/// handler.
|
||||
///
|
||||
/// Note this differs from [`routing::Layered`](crate::routing::Layered)
|
||||
/// Note this differs from [`routing::Router::layer`](crate::routing::Router::layer)
|
||||
/// which adds a middleware to a group of routes.
|
||||
///
|
||||
/// # Example
|
||||
|
|
|
@ -260,13 +260,13 @@ impl<S> Router<S> {
|
|||
ResBody: http_body::Body<Data = Bytes> + Send + Sync + 'static,
|
||||
ResBody::Error: Into<BoxError>,
|
||||
{
|
||||
self.map(|svc| {
|
||||
self.layer(
|
||||
ServiceBuilder::new()
|
||||
.layer_fn(BoxRoute)
|
||||
.layer_fn(CloneBoxService::new)
|
||||
.layer(MapResponseBodyLayer::new(box_body))
|
||||
.service(svc)
|
||||
})
|
||||
.into_inner(),
|
||||
)
|
||||
}
|
||||
|
||||
/// Apply a [`tower::Layer`] to the router.
|
||||
|
@ -336,11 +336,11 @@ impl<S> Router<S> {
|
|||
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
||||
/// # };
|
||||
/// ```
|
||||
pub fn layer<L>(self, layer: L) -> Router<Layered<L::Service>>
|
||||
pub fn layer<L>(self, layer: L) -> Router<L::Service>
|
||||
where
|
||||
L: Layer<S>,
|
||||
{
|
||||
self.map(|svc| Layered::new(layer.layer(svc)))
|
||||
self.map(|svc| layer.layer(svc))
|
||||
}
|
||||
|
||||
/// Convert this router into a [`MakeService`], that is a [`Service`] who's
|
||||
|
@ -891,58 +891,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// A [`Service`] created from a router by applying a Tower middleware.
|
||||
///
|
||||
/// Created with [`Router::layer`]. See that method for more details.
|
||||
pub struct Layered<S> {
|
||||
inner: S,
|
||||
}
|
||||
|
||||
impl<S> Layered<S> {
|
||||
fn new(inner: S) -> Self {
|
||||
Self { inner }
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Clone for Layered<S>
|
||||
where
|
||||
S: Clone,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self::new(self.inner.clone())
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> fmt::Debug for Layered<S>
|
||||
where
|
||||
S: fmt::Debug,
|
||||
{
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("Layered")
|
||||
.field("inner", &self.inner)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, R> Service<R> for Layered<S>
|
||||
where
|
||||
S: Service<R>,
|
||||
{
|
||||
type Response = S::Response;
|
||||
type Error = S::Error;
|
||||
type Future = S::Future;
|
||||
|
||||
#[inline]
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
self.inner.poll_ready(cx)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn call(&mut self, req: R) -> Self::Future {
|
||||
self.inner.call(req)
|
||||
}
|
||||
}
|
||||
|
||||
/// A [`Service`] that has been nested inside a router at some path.
|
||||
///
|
||||
/// Created with [`Router::nest`].
|
||||
|
@ -1144,9 +1092,6 @@ mod tests {
|
|||
assert_send::<BoxRoute<(), ()>>();
|
||||
assert_sync::<BoxRoute<(), ()>>();
|
||||
|
||||
assert_send::<Layered<()>>();
|
||||
assert_sync::<Layered<()>>();
|
||||
|
||||
assert_send::<Nested<(), ()>>();
|
||||
assert_sync::<Nested<(), ()>>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue