tower_timeout/
layer.rs

1use crate::Timeout;
2use std::time::Duration;
3use tower_layer::Layer;
4
5/// Applies a timeout to requests via the supplied inner service.
6#[derive(Debug)]
7pub struct TimeoutLayer {
8    timeout: Duration,
9}
10
11impl TimeoutLayer {
12    /// Create a timeout from a duration
13    pub fn new(timeout: Duration) -> Self {
14        TimeoutLayer { timeout }
15    }
16}
17
18impl<S> Layer<S> for TimeoutLayer {
19    type Service = Timeout<S>;
20
21    fn layer(&self, service: S) -> Self::Service {
22        Timeout::new(service, self.timeout)
23    }
24}