pub struct ConcurrencyLimit { /* private fields */ }Expand description
Bounds execution and waiting, returning 503 with Retry-After on overload.
Defaults to one queue slot per execution slot and a five-second queue
deadline. Permits normally end at response production. hold_body(true)
retains them until body completion, error or drop. Upgraded connections
require their own lifecycle budget. Clones share admission and counters.
Implementations§
Source§impl ConcurrencyLimit
impl ConcurrencyLimit
Sourcepub fn new(max: usize) -> Self
pub fn new(max: usize) -> Self
Configure execution capacity, treating zero as one for compatibility.
Args: max: Maximum active requests, at most Semaphore::MAX_PERMITS.
Returns: Bounded limit; invalid oversized configuration fails requests.
Sourcepub fn try_new(max: usize) -> Result<Self, ConcurrencyLimitError>
pub fn try_new(max: usize) -> Result<Self, ConcurrencyLimitError>
Validate a strictly positive execution capacity immediately.
Args: max: Maximum active requests.
Returns: Configured limit or invalid-capacity error.
Sourcepub fn queue(self, max: usize, timeout: Duration) -> Self
pub fn queue(self, max: usize, timeout: Duration) -> Self
Set bounded queue capacity and deadline, including a zero-slot queue.
Args: max: Maximum waiting requests, at most Semaphore::MAX_PERMITS. timeout: Maximum admission wait; zero means immediate admission.
Returns: Fresh admission state; existing clones keep their previous state.
Sourcepub fn hold_body(self, enabled: bool) -> Self
pub fn hold_body(self, enabled: bool) -> Self
Include response-body consumption in the execution limit.
Args: enabled: Retain permits until body completion, error or drop.
Returns: Layer sharing its original admission state.
Sourcepub fn close(&self)
pub fn close(&self)
Close admission and wake waiters; already active work can complete.
Returns: No value; all clones observe the closed state.
Sourcepub fn stats(&self) -> ConcurrencyStats
pub fn stats(&self) -> ConcurrencyStats
Read an approximate concurrent snapshot without locking.
Returns: Current capacities and cumulative admission counters.
Trait Implementations§
Source§impl Clone for ConcurrencyLimit
impl Clone for ConcurrencyLimit
Source§fn clone(&self) -> ConcurrencyLimit
fn clone(&self) -> ConcurrencyLimit
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ConcurrencyLimit
impl Debug for ConcurrencyLimit
Source§impl Layer<BoxCloneSyncService<Request<Body>, Response<Body>, Infallible>> for ConcurrencyLimit
impl Layer<BoxCloneSyncService<Request<Body>, Response<Body>, Infallible>> for ConcurrencyLimit
Source§type Service = BoxCloneSyncService<Request<Body>, Response<Body>, Infallible>
type Service = BoxCloneSyncService<Request<Body>, Response<Body>, Infallible>
Source§fn layer(&self, inner: BoxService) -> Self::Service
fn layer(&self, inner: BoxService) -> Self::Service
Auto Trait Implementations§
impl Freeze for ConcurrencyLimit
impl RefUnwindSafe for ConcurrencyLimit
impl Send for ConcurrencyLimit
impl Sync for ConcurrencyLimit
impl Unpin for ConcurrencyLimit
impl UnsafeUnpin for ConcurrencyLimit
impl UnwindSafe for ConcurrencyLimit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> ServiceExt for T
impl<T> ServiceExt for T
§fn compression(self) -> Compression<Self>where
Self: Sized,
fn compression(self) -> Compression<Self>where
Self: Sized,
§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
§fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
§fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
§fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
§fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
§fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
§fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
§fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_request_id<M>(
self,
header_name: HeaderName,
make_request_id: M,
) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
§fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
fn set_x_request_id<M>(self, make_request_id: M) -> SetRequestId<Self, M>where
Self: Sized,
M: MakeRequestId,
x-request-id as the header name. Read more§fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_request_id(
self,
header_name: HeaderName,
) -> PropagateRequestId<Self>where
Self: Sized,
§fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
fn propagate_x_request_id(self) -> PropagateRequestId<Self>where
Self: Sized,
x-request-id as the header name. Read more§fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
fn request_body_limit(self, limit: usize) -> RequestBodyLimit<Self>where
Self: Sized,
413 Payload Too Large responses. Read more