1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Layer traits and extensions.
//!
//! A layer decorates an service and provides additional functionality. It
//! allows other services to be composed with the service that implements layer.
//!
//! A middleware implements the [`Layer`] and [`Service`] trait.
//!
//! [`Service`]: crate::Service
pub use *;
pub use ;
/// Decorates a [`Service`], transforming either the request or the response.
///
/// Often, many of the pieces needed for writing network applications can be
/// reused across multiple services. The `Layer` trait can be used to write
/// reusable components that can be applied to very different kinds of services;
/// for example, it can be applied to services operating on different protocols,
/// and to both the client and server side of a network transaction.
///
/// # Example
///
/// ```rust
/// use motore::{layer::Layer, timeout::Timeout, BoxError, Service};
///
/// #[derive(Clone)]
/// pub struct TimeoutLayer {
/// duration: Option<std::time::Duration>,
/// }
///
/// impl TimeoutLayer {
/// pub fn new(duration: Option<std::time::Duration>) -> Self {
/// TimeoutLayer { duration }
/// }
/// }
///
/// impl<S> Layer<S> for TimeoutLayer {
/// type Service = Timeout<S>;
///
/// fn layer(self, inner: S) -> Self::Service {
/// Timeout::new(inner, self.duration)
/// }
/// }
/// ```
/// [`Service`]: crate::Service