pub struct CheckpointBudget {
pub max_bytes: usize,
pub used_bytes: usize,
}Expand description
Fields§
§max_bytes: usizeMaximum permitted allocation in bytes.
used_bytes: usizeCurrently allocated bytes.
Implementations§
Source§impl CheckpointBudget
impl CheckpointBudget
Sourcepub fn new(max_bytes: usize) -> Self
pub fn new(max_bytes: usize) -> Self
Create a fresh budget with max_bytes capacity and zero usage.
Sourcepub fn utilization(&self) -> f32
pub fn utilization(&self) -> f32
Fraction of the budget that has been consumed (used / max).
Returns 0.0 when max_bytes == 0 to avoid division by zero.
Sourcepub fn can_allocate(&self, bytes: usize) -> bool
pub fn can_allocate(&self, bytes: usize) -> bool
Whether bytes can be allocated without exceeding the budget.
Sourcepub fn allocate(&mut self, bytes: usize) -> Result<(), CheckpointError>
pub fn allocate(&mut self, bytes: usize) -> Result<(), CheckpointError>
Attempt to allocate bytes.
On success, used_bytes increases by bytes.
On failure, returns CheckpointError::BudgetExceeded and leaves
used_bytes unchanged.
Trait Implementations§
Source§impl Clone for CheckpointBudget
impl Clone for CheckpointBudget
Source§fn clone(&self) -> CheckpointBudget
fn clone(&self) -> CheckpointBudget
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 moreAuto Trait Implementations§
impl Freeze for CheckpointBudget
impl RefUnwindSafe for CheckpointBudget
impl Send for CheckpointBudget
impl Sync for CheckpointBudget
impl Unpin for CheckpointBudget
impl UnsafeUnpin for CheckpointBudget
impl UnwindSafe for CheckpointBudget
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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