pub struct HTB<T> {
pub unit_cost: u64,
/* private fields */
}
Expand description
Hierarchical Token Bucket structure
You can advance time for HTB structure using advance
and
advance_ns
and examine/alter internal state using
peek
/take
.
When several buckets are feeding from a single parent earlier one gets a priority
Fields§
§unit_cost: u64
Normalized unit cost, each nanosecond corresponds to this many units
Implementations§
Source§impl<T> HTB<T>
impl<T> HTB<T>
Sourcepub fn new(tokens: &[BucketCfg<T>]) -> Result<Self, Error>
pub fn new(tokens: &[BucketCfg<T>]) -> Result<Self, Error>
Create HTB for a given bucket configuration
Buckets should be given in depth first search traversal order:
- root with
parent
set to None - higher priority child of the root
- followed by high priority child of the child, if any, etc.
- followed by the next child
§Errors
If bucket configuration is invalid - returns an Error
type describing a problem
Sourcepub fn advance_ns(&mut self, time_diff: u64)
pub fn advance_ns(&mut self, time_diff: u64)
Sourcepub fn advance(&mut self, time_diff: Duration)
pub fn advance(&mut self, time_diff: Duration)
Advance time by Duration
Updates internal structure, see also advance_ns
Sourcepub fn peek(&self, label: T) -> bool
pub fn peek(&self, label: T) -> bool
Check if there’s at least one token available at index T
See also peek_n
Trait Implementations§
impl<T> StructuralPartialEq for HTB<T>
Auto Trait Implementations§
impl<T> Freeze for HTB<T>
impl<T> RefUnwindSafe for HTB<T>where
T: RefUnwindSafe,
impl<T> Send for HTB<T>where
T: Send,
impl<T> Sync for HTB<T>where
T: Sync,
impl<T> Unpin for HTB<T>where
T: Unpin,
impl<T> UnwindSafe for HTB<T>where
T: UnwindSafe,
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