pub struct BucketState { /* private fields */ }Expand description
The mutable half of a token bucket: what it holds and when it was last refilled.
Session-scoped and shared by every stream of a class, so it is the
scheduler’s state and not a stream’s. Kept separate from
BucketConfig so the configuration stays comparable and cloneable
while the state stays exactly one owner’s.
Implementations§
Source§impl BucketState
impl BucketState
Sourcepub fn new(burst_bytes: u64, now: Instant) -> Self
pub fn new(burst_bytes: u64, now: Instant) -> Self
A bucket that starts full at burst_bytes, as of now.
Starting full is what makes the first unit of a session go
immediately; starting empty would put a burst_bytes / rate_bps
delay in front of every stream and read as a broken proxy.
Sourcepub fn available_bytes(&self) -> u64
pub fn available_bytes(&self) -> u64
Whole bytes currently held, as of the last charge.
Does not refill: this is a read of recorded state, not a clock reading, so it stays usable from a test that fabricates its own instants.
Trait Implementations§
Source§impl Clone for BucketState
impl Clone for BucketState
Source§fn clone(&self) -> BucketState
fn clone(&self) -> BucketState
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for BucketState
Source§impl Debug for BucketState
impl Debug for BucketState
impl Eq for BucketState
Source§impl PartialEq for BucketState
impl PartialEq for BucketState
impl StructuralPartialEq for BucketState
Auto Trait Implementations§
impl Freeze for BucketState
impl RefUnwindSafe for BucketState
impl Send for BucketState
impl Sync for BucketState
impl Unpin for BucketState
impl UnsafeUnpin for BucketState
impl UnwindSafe for BucketState
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