tower_layer/
identity.rs

1use super::Layer;
2use 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)]
11pub struct Identity {
12    _p: (),
13}
14
15impl Identity {
16    /// Create a new [`Identity`] value
17    pub const 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
25impl<S> Layer<S> for Identity {
26    type Service = S;
27
28    fn layer(&self, inner: S) -> Self::Service {
29        inner
30    }
31}
32
33impl fmt::Debug for Identity {
34    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35        f.debug_struct("Identity").finish()
36    }
37}