[][src]Struct governor::DirectRateLimiter

pub struct DirectRateLimiter<C: Clock = DefaultClock> { /* fields omitted */ }

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]

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 returns Ok(()).
  • 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

impl<C: Debug + Clock> Debug for DirectRateLimiter<C> where
    C::Instant: Debug
[src]

Auto Trait Implementations

impl<C> Send for DirectRateLimiter<C> where
    C: Send,
    <C as Clock>::Instant: Send

impl<C> Sync for DirectRateLimiter<C> where
    C: Sync,
    <C as Clock>::Instant: Sync

impl<C> Unpin for DirectRateLimiter<C> where
    C: Unpin,
    <C as Clock>::Instant: Unpin

impl<C> UnwindSafe for DirectRateLimiter<C> where
    C: UnwindSafe,
    <C as Clock>::Instant: UnwindSafe

impl<C> RefUnwindSafe for DirectRateLimiter<C> where
    C: RefUnwindSafe,
    <C as Clock>::Instant: RefUnwindSafe

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,