tower_limit/concurrency/
layer.rs

1use super::ConcurrencyLimit;
2use tower_layer::Layer;
3
4/// Enforces a limit on the concurrent number of requests the underlying
5/// service can handle.
6#[derive(Debug, Clone)]
7pub struct ConcurrencyLimitLayer {
8    max: usize,
9}
10
11impl ConcurrencyLimitLayer {
12    /// Create a new concurrency limit layer.
13    pub fn new(max: usize) -> Self {
14        ConcurrencyLimitLayer { max }
15    }
16}
17
18impl<S> Layer<S> for ConcurrencyLimitLayer {
19    type Service = ConcurrencyLimit<S>;
20
21    fn layer(&self, service: S) -> Self::Service {
22        ConcurrencyLimit::new(service, self.max)
23    }
24}