pub struct LimitLoadBalancer<T>{ /* private fields */ }Expand description
A load balancer that limits the number of allocations per entry over a specified time interval.
This implementation supports both async and sync allocation.
Implementations§
Source§impl<T> LimitLoadBalancer<T>
impl<T> LimitLoadBalancer<T>
Sourcepub fn new(entries: Vec<(u64, T)>) -> Self
pub fn new(entries: Vec<(u64, T)>) -> Self
Create a new LimitLoadBalancer with the default interval of 1 second.
§Arguments
entries- A vector of tuples(max_count, value).
Sourcepub fn new_interval(entries: Vec<(u64, T)>, interval: Duration) -> Self
pub fn new_interval(entries: Vec<(u64, T)>, interval: Duration) -> Self
Create a new LimitLoadBalancer with a custom interval duration.
§Arguments
entries- A vector of tuples(max_count, value).interval- Duration after which allocation counts are reset.
Sourcepub async fn update<F, R, N>(&self, handle: F) -> Result<N>
pub async fn update<F, R, N>(&self, handle: F) -> Result<N>
Update the load balancer using an async callback.
Sourcepub async fn alloc_skip(&self, index: usize) -> (usize, T)
pub async fn alloc_skip(&self, index: usize) -> (usize, T)
Asynchronously allocate an entry, skipping the specified index. Loops until a valid entry is found.
Sourcepub fn try_alloc_skip(&self, index: usize) -> Option<(usize, T)>
pub fn try_alloc_skip(&self, index: usize) -> Option<(usize, T)>
Try to allocate an entry without awaiting.
Returns None immediately if no entry is available.
Trait Implementations§
Source§impl<T> BoxLoadBalancer<T> for LimitLoadBalancer<T>
impl<T> BoxLoadBalancer<T> for LimitLoadBalancer<T>
Source§impl<T> Clone for LimitLoadBalancer<T>
impl<T> Clone for LimitLoadBalancer<T>
Source§fn clone(&self) -> LimitLoadBalancer<T>
fn clone(&self) -> LimitLoadBalancer<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for LimitLoadBalancer<T>
impl<T> !RefUnwindSafe for LimitLoadBalancer<T>
impl<T> Send for LimitLoadBalancer<T>
impl<T> Sync for LimitLoadBalancer<T>
impl<T> Unpin for LimitLoadBalancer<T>
impl<T> !UnwindSafe for LimitLoadBalancer<T>
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