Move layer::{LayerExt, Chain, Identity} (#216)
- `tower-layer` util types are now in `tower-util`. - `LayerExt` is now in `tower`. This sets the stage for adding layer specific extension fns.
This commit is contained in:
parent
2448ca9cdc
commit
019129829c
|
@ -22,7 +22,3 @@ tower-service = "0.2.0"
|
|||
|
||||
[dev-dependencies]
|
||||
void = "1"
|
||||
|
||||
[features]
|
||||
default = ["util"]
|
||||
util = []
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
#![deny(missing_docs)]
|
||||
#![doc(html_root_url = "https://docs.rs/tower-layer/0.1.0")]
|
||||
|
||||
//! Layer traits and extensions.
|
||||
//!
|
||||
//! A layer decorates an service and provides additional functionality. It
|
||||
|
@ -5,18 +8,9 @@
|
|||
//!
|
||||
//! A middleware implements the [`Layer`] and [`Service`] trait.
|
||||
|
||||
#![deny(missing_docs)]
|
||||
#![doc(html_root_url = "https://docs.rs/tower-layer/0.1.0")]
|
||||
|
||||
extern crate futures;
|
||||
extern crate tower_service;
|
||||
|
||||
#[cfg(feature = "util")]
|
||||
pub mod util;
|
||||
|
||||
#[cfg(feature = "util")]
|
||||
pub use util::LayerExt;
|
||||
|
||||
use tower_service::Service;
|
||||
|
||||
/// Decorates a `Service`, transforming either the request or the response.
|
||||
|
|
|
@ -1,27 +0,0 @@
|
|||
//! Types and utilities for working with `Layer`.
|
||||
|
||||
use Layer;
|
||||
|
||||
mod chain;
|
||||
mod identity;
|
||||
|
||||
pub use self::chain::Chain;
|
||||
pub use self::identity::Identity;
|
||||
|
||||
/// An extension trait for `Layer`'s that provides a variety of convenient
|
||||
/// adapters.
|
||||
pub trait LayerExt<S, Request>: Layer<S, Request> {
|
||||
/// Return a new `Layer` instance that applies both `self` and
|
||||
/// `middleware` to services being wrapped.
|
||||
///
|
||||
/// This defines a middleware stack.
|
||||
fn chain<T>(self, middleware: T) -> Chain<Self, T>
|
||||
where
|
||||
T: Layer<Self::Service, Request>,
|
||||
Self: Sized,
|
||||
{
|
||||
Chain::new(self, middleware)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, Request> LayerExt<S, Request> for T where T: Layer<S, Request> {}
|
|
@ -24,8 +24,9 @@ io = ["tokio-io"]
|
|||
[dependencies]
|
||||
either = { version = "1.5.1", optional = true }
|
||||
futures = "0.1.23"
|
||||
tower-service = "0.2.0"
|
||||
tokio-io = { version = "0.1.12", optional = true }
|
||||
tower-service = "0.2.0"
|
||||
tower-layer = { version = "0.1.0", path = "../tower-layer" }
|
||||
|
||||
[dev-dependencies]
|
||||
tokio-mock-task = "0.1"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use tower_layer::Layer;
|
||||
use tower_service::Service;
|
||||
use Layer;
|
||||
|
||||
/// Two middlewares chained together.
|
||||
///
|
|
@ -1,6 +1,6 @@
|
|||
use std::fmt;
|
||||
use tower_layer::Layer;
|
||||
use tower_service::Service;
|
||||
use Layer;
|
||||
|
||||
/// A no-op middleware.
|
||||
///
|
|
@ -0,0 +1,5 @@
|
|||
mod chain;
|
||||
mod identity;
|
||||
|
||||
pub use self::chain::Chain;
|
||||
pub use self::identity::Identity;
|
|
@ -6,12 +6,14 @@ extern crate either as _either;
|
|||
extern crate futures;
|
||||
#[cfg(feature = "io")]
|
||||
extern crate tokio_io;
|
||||
extern crate tower_layer;
|
||||
extern crate tower_service;
|
||||
|
||||
mod boxed;
|
||||
mod call_all;
|
||||
#[cfg(feature = "either")]
|
||||
mod either;
|
||||
pub mod layer;
|
||||
#[cfg(feature = "io")]
|
||||
mod make_connection;
|
||||
mod make_service;
|
||||
|
|
|
@ -4,11 +4,9 @@ mod service;
|
|||
|
||||
pub use self::service::{LayeredMakeService, ServiceFuture};
|
||||
|
||||
use tower_layer::{
|
||||
util::{Chain, Identity},
|
||||
Layer,
|
||||
};
|
||||
use tower_layer::Layer;
|
||||
use tower_service::Service;
|
||||
use tower_util::layer::{Chain, Identity};
|
||||
use tower_util::MakeService;
|
||||
|
||||
pub(super) type Error = Box<::std::error::Error + Send + Sync>;
|
||||
|
|
|
@ -7,3 +7,24 @@ pub use tower_load_shed::LoadShedLayer;
|
|||
pub use tower_rate_limit::RateLimitLayer;
|
||||
pub use tower_retry::RetryLayer;
|
||||
pub use tower_timeout::TimeoutLayer;
|
||||
|
||||
use tower_layer::Layer;
|
||||
use tower_util::layer::Chain;
|
||||
|
||||
/// An extension trait for `Layer`'s that provides a variety of convenient
|
||||
/// adapters.
|
||||
pub trait LayerExt<S, Request>: Layer<S, Request> {
|
||||
/// Return a new `Layer` instance that applies both `self` and
|
||||
/// `middleware` to services being wrapped.
|
||||
///
|
||||
/// This defines a middleware stack.
|
||||
fn chain<T>(self, middleware: T) -> Chain<Self, T>
|
||||
where
|
||||
T: Layer<Self::Service, Request>,
|
||||
Self: Sized,
|
||||
{
|
||||
Chain::new(self, middleware)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, Request> LayerExt<S, Request> for T where T: Layer<S, Request> {}
|
||||
|
|
Loading…
Reference in New Issue