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§
Source§impl Allower
impl Allower
Sourcepub fn ratelimiter() -> DirectRateLimiter<Allower, ForeverClock>
pub fn ratelimiter() -> DirectRateLimiter<Allower, ForeverClock>
Return a rate-limiter that lies, i.e. that allows all requests through.
Trait Implementations§
Source§impl Algorithm<Always> for Allower
impl Algorithm<Always> for Allower
Source§fn test_n_and_update(
&self,
_state: &Self::BucketState,
_n: u32,
_t0: Always,
) -> Result<(), NegativeMultiDecision<Impossible>>
fn test_n_and_update( &self, _state: &Self::BucketState, _n: u32, _t0: Always, ) -> Result<(), NegativeMultiDecision<Impossible>>
Allows all cells through unconditionally.
Source§type BucketState = ()
type BucketState = ()
The state of a single rate limiting bucket. Read more
Source§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.Source§fn 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
.Source§fn test_and_update(
&self,
state: &Self::BucketState,
at: P,
) -> Result<(), Self::NegativeDecision>
fn test_and_update( &self, state: &Self::BucketState, at: P, ) -> 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 moreimpl Copy for Allower
Auto Trait Implementations§
impl Freeze for Allower
impl RefUnwindSafe for Allower
impl Send for Allower
impl Sync for Allower
impl Unpin for Allower
impl UnwindSafe for Allower
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
Mutably borrows from an owned value. Read more