pub struct TransferBudget { /* private fields */ }Expand description
Rolling byte accounting against a set of TransferLimits.
Implementations§
Source§impl TransferBudget
impl TransferBudget
pub const fn new(limits: TransferLimits) -> Self
pub fn limits(&self) -> TransferLimits
Sourcepub fn set_limits(&self, limits: TransferLimits)
pub fn set_limits(&self, limits: TransferLimits)
Replace the active quotas without discarding recorded usage.
Sourcepub fn available(&self, direction: Direction) -> u64
pub fn available(&self, direction: Direction) -> u64
Bytes that may still be transferred for direction right now.
Sourcepub fn available_at(&self, direction: Direction, now: Instant) -> u64
pub fn available_at(&self, direction: Direction, now: Instant) -> u64
Bytes that may still be transferred for direction at now.
The result is the smallest remaining allowance across the configured
rolling windows, or u64::MAX when the direction is unlimited.
Sourcepub fn can_transfer(&self, direction: Direction, bytes: u64) -> bool
pub fn can_transfer(&self, direction: Direction, bytes: u64) -> bool
Whether bytes can be transferred for direction without breaking a quota.
Sourcepub fn record_at(&self, direction: Direction, bytes: u64, now: Instant)
pub fn record_at(&self, direction: Direction, bytes: u64, now: Instant)
Record transferred bytes observed at now.
Sourcepub fn used_at(
&self,
direction: Direction,
window: Duration,
now: Instant,
) -> u64
pub fn used_at( &self, direction: Direction, window: Duration, now: Instant, ) -> u64
Bytes transferred for direction within window ending at now.
Sourcepub fn recorded_total(&self) -> u64
pub fn recorded_total(&self) -> u64
Total bytes recorded in all windows (diagnostics).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TransferBudget
impl RefUnwindSafe for TransferBudget
impl Send for TransferBudget
impl Sync for TransferBudget
impl Unpin for TransferBudget
impl UnsafeUnpin for TransferBudget
impl UnwindSafe for TransferBudget
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more