Struct ratelimit_meter::example_algorithms::Allower
source · pub struct Allower {}
Expand description
The most naive implementation of a rate-limiter ever: Always allows every cell through.
Example
use ratelimit_meter::DirectRateLimiter;
use ratelimit_meter::example_algorithms::Allower;
let mut allower = Allower::ratelimiter();
assert!(allower.check().is_ok());
Implementations
sourceimpl Allower
impl Allower
sourcepub fn ratelimiter() -> DirectRateLimiter<Allower>
pub fn ratelimiter() -> DirectRateLimiter<Allower>
Return a rate-limiter that lies, i.e. that allows all requests through.
Trait Implementations
sourceimpl Algorithm for Allower
impl Algorithm for Allower
sourcefn test_n_and_update(
&self,
_state: &Self::BucketState,
_n: u32,
_t0: Instant
) -> Result<(), NegativeMultiDecision<Impossible>>
fn test_n_and_update(
&self,
_state: &Self::BucketState,
_n: u32,
_t0: Instant
) -> Result<(), NegativeMultiDecision<Impossible>>
Allows all cells through unconditionally.
type BucketState = ()
type BucketState = ()
The state of a single rate limiting bucket. Read more
type NegativeDecision = Impossible
type NegativeDecision = Impossible
The type returned when a rate limiting decision for a single
cell is negative. Each rate limiting algorithm can decide to
return the type that suits it best, but most algorithms’
decisions also implement
NonConformance
, to ease
handling of how long to wait. Read moresourcefn construct(
_capacity: NonZeroU32,
_cell_weight: NonZeroU32,
_per_time_unit: Duration
) -> Result<Self, InconsistentCapacity>
fn construct(
_capacity: NonZeroU32,
_cell_weight: NonZeroU32,
_per_time_unit: Duration
) -> Result<Self, InconsistentCapacity>
Constructs a rate limiter with the given parameters:
capacity
is the number of cells to allow, weighing
cell_weight
, every per_time_unit
. Read moresourcefn test_and_update(
&self,
state: &Self::BucketState,
at: Instant
) -> Result<(), Self::NegativeDecision>
fn test_and_update(
&self,
state: &Self::BucketState,
at: Instant
) -> Result<(), Self::NegativeDecision>
Tests if a single cell can be accommodated in the rate limiter
at the instant
at
and updates the rate-limiter state to
account for the weight of the cell. Read moresourceimpl RateLimitState<Allower> for ()
impl RateLimitState<Allower> for ()
sourcefn last_touched(&self, _params: &Allower) -> Instant
fn last_touched(&self, _params: &Allower) -> Instant
Returns the last time instant that the state had any relevance
(i.e. the rate limiter would behave exactly as if it was a new
rate limiter after this time). Read more
impl Copy for Allower
Auto Trait Implementations
impl RefUnwindSafe for Allower
impl Send for Allower
impl Sync for Allower
impl Unpin for Allower
impl UnwindSafe for Allower
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more