Struct ratelimit_meter::Threadsafe [] [src]

pub struct Threadsafe<Impl> where
    Impl: Decider + Sized + Clone
{ /* fields omitted */ }

A wrapper that ensures operations in otherwise thread-unsafe rate-limiting decision algorithms are thread-safe. This is implemented by wrapping the actual Decider implementation in an atomically reference-counted mutex. It takes out a mutex whenever .test_and_update() is called.

Methods

impl<Impl> Threadsafe<Impl> where
    Impl: Decider + Sized + Clone
[src]

[src]

Trait Implementations

impl<Impl: Clone> Clone for Threadsafe<Impl> where
    Impl: Decider + Sized + Clone
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl<Impl> DeciderImpl for Threadsafe<Impl> where
    Impl: Decider + Sized + Clone
[src]

The (optional) type for additional information on negative decisions. Read more

[src]

Tests if a single cell can be accomodated in the rate limiter at the instant at and updates the rate-limiter to account for the weight of the cell. Read more

impl<Impl> Decider for Threadsafe<Impl> where
    Impl: Decider + Sized + Clone
[src]

[src]

Tests if a single cell can be accomodated at Instant::now(). See check_at. Read more

[src]

Tests is a single cell can be accomodated at the given time stamp. Read more

impl<'a> From<&'a Builder> for Threadsafe<GCRA>
[src]

Allows converting from a GCRA builder directly into a threadsafe GCRA decider. For example:

Example

use ratelimit_meter::{GCRA, Decider, Threadsafe, Decision};
let mut gcra_sync: Threadsafe<GCRA> = GCRA::for_capacity(50).into();
assert_eq!(Decision::Yes, gcra_sync.check().unwrap());

[src]

Performs the conversion.

impl<'a> From<Builder> for Threadsafe<GCRA>
[src]

Allows converting from a GCRA builder directly into a threadsafe GCRA decider. Same as the borrowed implementation, except for owned Builders.

[src]

Performs the conversion.