[−][src]Struct governor::DirectRateLimiter
An in-memory rate limiter that makes direct (un-keyed) rate-limiting decisions. Direct rate limiters can be used to e.g. regulate the transmission of packets on a single connection, or to ensure that an API client stays within a service's rate limit.
Methods
impl<C: Clock<Instant = Instant>> DirectRateLimiter<C>
[src]
pub async fn until_ready<'_>(&'_ self)
[src]
Returns a future that resolves as soon as the rate limiter allows it.
impl DirectRateLimiter<DefaultClock>
[src]
pub fn new(quota: Quota) -> Self
[src]
Construct a new direct rate limiter for a quota with the default clock.
impl<C: Clock> DirectRateLimiter<C>
[src]
pub fn check(&self) -> Result<(), NotUntil<C::Instant>>
[src]
Allow a single cell through the rate limiter.
If the rate limit is reached, check
returns information about the earliest
time that a cell might be allowed through again.
pub fn check_all(
&self,
n: NonZeroU32
) -> Result<(), NegativeMultiDecision<NotUntil<C::Instant>>>
[src]
&self,
n: NonZeroU32
) -> Result<(), NegativeMultiDecision<NotUntil<C::Instant>>>
Allow only all n
cells through the rate limiter.
This method can succeed in only one way and fail in two ways:
- Success: If all
n
cells can be accommodated, it returnsOk(())
. - Failure (but ok): Not all cells can make it through at the current time.
The result is
Err(NegativeMultiDecision::BatchNonConforming(NotUntil))
, which can be interrogated about when the batch might next conform. - Failure (the batch can never go through): The rate limit is too low for the given number of cells.
Performance
This method diverges a little from the GCRA algorithm, using multiplication to determine the next theoretical arrival time, and so is not as fast as checking a single cell.
pub fn new_with_clock(quota: Quota, clock: &C) -> DirectRateLimiter<C>
[src]
Construct a new direct rate limiter with a custom clock.
Trait Implementations
Auto Trait Implementations
impl<C> Send for DirectRateLimiter<C> where
C: Send,
<C as Clock>::Instant: Send,
C: Send,
<C as Clock>::Instant: Send,
impl<C> Sync for DirectRateLimiter<C> where
C: Sync,
<C as Clock>::Instant: Sync,
C: Sync,
<C as Clock>::Instant: Sync,
impl<C> Unpin for DirectRateLimiter<C> where
C: Unpin,
<C as Clock>::Instant: Unpin,
C: Unpin,
<C as Clock>::Instant: Unpin,
impl<C> UnwindSafe for DirectRateLimiter<C> where
C: UnwindSafe,
<C as Clock>::Instant: UnwindSafe,
C: UnwindSafe,
<C as Clock>::Instant: UnwindSafe,
impl<C> RefUnwindSafe for DirectRateLimiter<C> where
C: RefUnwindSafe,
<C as Clock>::Instant: RefUnwindSafe,
C: RefUnwindSafe,
<C as Clock>::Instant: RefUnwindSafe,
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
ⓘImportant traits for &'_ mut Wfn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,