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]
Impl: Decider + Sized + Clone,
fn new(sub: Impl) -> Threadsafe<Impl>
[src]
Trait Implementations
impl<Impl: Clone> Clone for Threadsafe<Impl> where
Impl: Decider + Sized + Clone,
[src]
Impl: Decider + Sized + Clone,
fn clone(&self) -> Threadsafe<Impl>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<Impl> DeciderImpl for Threadsafe<Impl> where
Impl: Decider + Sized + Clone,
[src]
Impl: Decider + Sized + Clone,
type T = Impl::T
The (optional) type for additional information on negative decisions. Read more
fn test_and_update(&mut self, at: Instant) -> Result<Decision<Impl::T>>
[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]
Impl: Decider + Sized + Clone,
fn check(&mut self) -> Result<Decision<Self::T>>
[src]
Tests if a single cell can be accomodated at Instant::now()
. See check_at
. Read more
fn check_at(&mut self, at: Instant) -> Result<Decision<Self::T>>
[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());
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 Builder
s.