pub struct ByteBudget(/* private fields */);Expand description
Child usage is included in every ancestor; creating children does not multiply the parent limit. Names are static component names, not tenant identifiers or unbounded metric labels. Dropping the last child handle and reservation releases its metadata without retaining a central registry.
Implementations§
Source§impl ByteBudget
impl ByteBudget
Sourcepub fn new(name: &'static str, limit: usize) -> Result<Self, ResourceError>
pub fn new(name: &'static str, limit: usize) -> Result<Self, ResourceError>
Create a root budget labelled name with the given byte limit.
§Errors
Returns ResourceError::Invalid if limit is zero.
Sourcepub fn child(
&self,
name: &'static str,
limit: usize,
) -> Result<Self, ResourceError>
pub fn child( &self, name: &'static str, limit: usize, ) -> Result<Self, ResourceError>
Create a child budget whose usage is also charged to this budget.
§Errors
Returns ResourceError::Invalid if limit is zero or exceeds the
parent limit, or if nesting would exceed 32 levels.
Sourcepub fn snapshot(&self) -> BudgetSnapshot
pub fn snapshot(&self) -> BudgetSnapshot
Snapshot this budget’s limit, current usage, and peak usage.
Sourcepub fn available(&self) -> usize
pub fn available(&self) -> usize
Available in this budget AND every parent at one accounting instant.
§Panics
Panics if the ancestor chain is empty, which cannot happen because a budget always has at least itself.
Sourcepub fn try_reserve(
&self,
bytes: usize,
) -> Result<ByteReservation, ResourceError>
pub fn try_reserve( &self, bytes: usize, ) -> Result<ByteReservation, ResourceError>
Immediate admission, before allocation. Queueing, deadlines and fair scheduling are deliberately separate work; this never blocks for bytes.
§Errors
Returns ResourceError::Exhausted if this budget or any ancestor
cannot admit bytes.