1 use super::Layer; 2 use std::fmt; 3 4 /// A no-op middleware. 5 /// 6 /// When wrapping a [`Service`], the [`Identity`] layer returns the provided 7 /// service without modifying it. 8 /// 9 /// [`Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html 10 #[derive(Default, Clone)] 11 pub struct Identity { 12 _p: (), 13 } 14 15 impl Identity { 16 /// Create a new [`Identity`] value new() -> Identity17 pub fn new() -> Identity { 18 Identity { _p: () } 19 } 20 } 21 22 /// Decorates a [`Service`], transforming either the request or the response. 23 /// 24 /// [`Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html 25 impl<S> Layer<S> for Identity { 26 type Service = S; 27 layer(&self, inner: S) -> Self::Service28 fn layer(&self, inner: S) -> Self::Service { 29 inner 30 } 31 } 32 33 impl fmt::Debug for Identity { fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 35 f.debug_struct("Identity").finish() 36 } 37 } 38