pub struct ByteBudget { /* private fields */ }Expand description
Aggregate byte accounting beneath one immutable limit.
A budget maintains used <= limit. Successful operations update used;
rejected operations leave all observable state unchanged.
A live budget is deliberately neither cloneable nor defaultable, and its limit cannot be changed.
ⓘ
use bytebudget::{ByteBudget, ByteCount};
let budget = ByteBudget::new(ByteCount::new(8));
let _fork = budget.clone();ⓘ
use bytebudget::ByteBudget;
fn require_copy<T: Copy>() {}
require_copy::<ByteBudget>();ⓘ
use bytebudget::ByteBudget;
let _: ByteBudget = Default::default();ⓘ
use bytebudget::{ByteBudget, ByteCount};
let mut budget = ByteBudget::new(ByteCount::new(8));
budget.set_limit(ByteCount::new(16));Implementations§
Source§impl ByteBudget
impl ByteBudget
Sourcepub const fn new(limit: ByteCount) -> Self
pub const fn new(limit: ByteCount) -> Self
Creates an unused budget with the supplied fixed limit.
Sourcepub const fn can_reserve(&self, amount: ByteCount) -> bool
pub const fn can_reserve(&self, amount: ByteCount) -> bool
Returns whether amount can be reserved without exceeding the limit.
Sourcepub const fn is_exhausted(&self) -> bool
pub const fn is_exhausted(&self) -> bool
Returns whether no additional nonzero byte count can be reserved.
Sourcepub fn try_reserve(&mut self, amount: ByteCount) -> Result<(), CapacityExceeded>
pub fn try_reserve(&mut self, amount: ByteCount) -> Result<(), CapacityExceeded>
Reserves amount when it fits in the currently available capacity.
On failure, the returned error captures both the attempted amount and the capacity available at rejection, and the budget remains unchanged.
Trait Implementations§
Source§impl Debug for ByteBudget
impl Debug for ByteBudget
impl Eq for ByteBudget
Source§impl PartialEq for ByteBudget
impl PartialEq for ByteBudget
impl StructuralPartialEq for ByteBudget
Auto Trait Implementations§
impl Freeze for ByteBudget
impl RefUnwindSafe for ByteBudget
impl Send for ByteBudget
impl Sync for ByteBudget
impl Unpin for ByteBudget
impl UnsafeUnpin for ByteBudget
impl UnwindSafe for ByteBudget
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