mirror of
https://github.com/tower-rs/tower.git
synced 2025-10-02 07:20:52 +00:00
25 lines
523 B
Rust
25 lines
523 B
Rust
use crate::Timeout;
|
|
use std::time::Duration;
|
|
use tower_layer::Layer;
|
|
|
|
/// Applies a timeout to requests via the supplied inner service.
|
|
#[derive(Debug)]
|
|
pub struct TimeoutLayer {
|
|
timeout: Duration,
|
|
}
|
|
|
|
impl TimeoutLayer {
|
|
/// Create a timeout from a duration
|
|
pub fn new(timeout: Duration) -> Self {
|
|
TimeoutLayer { timeout }
|
|
}
|
|
}
|
|
|
|
impl<S> Layer<S> for TimeoutLayer {
|
|
type Service = Timeout<S>;
|
|
|
|
fn layer(&self, service: S) -> Self::Service {
|
|
Timeout::new(service, self.timeout)
|
|
}
|
|
}
|