pub struct Permit { /* private fields */ }Expand description
RAII permit that holds a semaphore slot for the lifetime of a handler task.
On the success path of ConnectionLimiter::acquire (acquire_inner),
the limiter calls Metrics::dispatch_permit_acquired() immediately before
constructing this struct; Drop calls Metrics::dispatch_permit_released()
unconditionally. The two calls must remain paired: every successful
construction is matched by exactly one drop, and the gauge stays balanced.
_sem is Option so the max_concurrent_handlers = 0 disabled-cap mode
can return a Permit without holding a semaphore slot — the in-flight
gauge still tracks the handler, and Drop releases nothing (the
OwnedSemaphorePermit is None).
#[must_use]: dropping the permit immediately (let _ = limiter.acquire(&conn);)
would defeat the purpose of acquiring it — the slot is freed before the
handler runs, so the cap fails to bound concurrency.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Permit
impl !UnwindSafe for Permit
impl Freeze for Permit
impl Send for Permit
impl Sync for Permit
impl Unpin for Permit
impl UnsafeUnpin for Permit
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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request