2019-11-29 13:09:47 -08:00
|
|
|
use super::Layer;
|
2019-05-09 08:44:40 -07:00
|
|
|
use std::fmt;
|
2019-03-24 13:53:09 -07:00
|
|
|
|
|
|
|
/// A no-op middleware.
|
|
|
|
///
|
|
|
|
/// When wrapping a `Service`, the `Identity` layer returns the provided
|
|
|
|
/// service without modifying it.
|
2019-05-09 08:44:40 -07:00
|
|
|
#[derive(Default, Clone)]
|
2019-03-24 13:53:09 -07:00
|
|
|
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.
|
2019-04-11 13:38:45 -07:00
|
|
|
impl<S> Layer<S> for Identity {
|
2019-03-24 13:53:09 -07:00
|
|
|
type Service = S;
|
|
|
|
|
2019-04-11 13:38:45 -07:00
|
|
|
fn layer(&self, inner: S) -> Self::Service {
|
|
|
|
inner
|
2019-03-24 13:53:09 -07:00
|
|
|
}
|
|
|
|
}
|
2019-05-09 08:44:40 -07:00
|
|
|
|
|
|
|
impl fmt::Debug for Identity {
|
2019-11-29 13:09:47 -08:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2019-05-09 08:44:40 -07:00
|
|
|
f.debug_struct("Identity").finish()
|
|
|
|
}
|
|
|
|
}
|