parent
db2f0ecfb3
commit
0e70f1320e
|
@ -0,0 +1,47 @@
|
|||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use tower_service::Service;
|
||||
use Layer;
|
||||
|
||||
/// A no-op middleware.
|
||||
///
|
||||
/// When wrapping a `Service`, the `Identity` layer returns the provided
|
||||
/// service without modifying it.
|
||||
#[derive(Debug, Default, Clone)]
|
||||
pub struct Identity {
|
||||
_p: (),
|
||||
}
|
||||
|
||||
impl Identity {
|
||||
/// Create a new `Identity` value
|
||||
pub fn new() -> Identity {
|
||||
Identity { _p: () }
|
||||
}
|
||||
}
|
||||
|
||||
/// Decorates a `Service`, transforming either the request or the response.
|
||||
impl<S, Request> Layer<S, Request> for Identity
|
||||
where
|
||||
S: Service<Request>,
|
||||
{
|
||||
type Response = S::Response;
|
||||
type Error = S::Error;
|
||||
type LayerError = Never;
|
||||
type Service = S;
|
||||
|
||||
fn layer(&self, inner: S) -> Result<Self::Service, Self::LayerError> {
|
||||
Ok(inner)
|
||||
}
|
||||
}
|
||||
|
||||
/// An error that can never occur.
|
||||
#[derive(Debug)]
|
||||
pub enum Never {}
|
||||
|
||||
impl fmt::Display for Never {
|
||||
fn fmt(&self, _: &mut fmt::Formatter) -> fmt::Result {
|
||||
match *self {}
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::error::Error for Never {}
|
|
@ -3,8 +3,10 @@
|
|||
use Layer;
|
||||
|
||||
mod chain;
|
||||
mod identity;
|
||||
|
||||
pub use self::chain::{Chain, ChainError};
|
||||
pub use self::identity::Identity;
|
||||
|
||||
/// An extension trait for `Layer`'s that provides a variety of convenient
|
||||
/// adapters.
|
||||
|
|
Loading…
Reference in New Issue