pub struct BudgetTracker { /* private fields */ }Expand description
Thread-safe accounting shared by a run and its descendants.
Implementations§
Source§impl BudgetTracker
impl BudgetTracker
Sourcepub fn restore(limit: Budget, usage: Usage) -> Result<Self, BudgetExceeded>
pub fn restore(limit: Budget, usage: Usage) -> Result<Self, BudgetExceeded>
Restores a tracker from a previously persisted usage snapshot.
§Errors
Returns BudgetExceeded when usage already exceeds limit.
Sourcepub fn try_consume(&self, delta: Usage) -> Result<Usage, BudgetExceeded>
pub fn try_consume(&self, delta: Usage) -> Result<Usage, BudgetExceeded>
Atomically consumes resources or leaves all counters unchanged.
§Errors
Returns BudgetExceeded when any cumulative counter would exceed its
configured limit or overflow.
Sourcepub fn try_reserve(
&self,
amount: Usage,
) -> Result<BudgetReservation, BudgetExceeded>
pub fn try_reserve( &self, amount: Usage, ) -> Result<BudgetReservation, BudgetExceeded>
Atomically reserves one scoped budget share.
§Errors
Returns BudgetExceeded without creating a reservation when the
requested share and all existing commitments exceed a hard limit.
Sourcepub fn try_reserve_batch(
&self,
amounts: impl IntoIterator<Item = Usage>,
) -> Result<Vec<BudgetReservation>, BudgetExceeded>
pub fn try_reserve_batch( &self, amounts: impl IntoIterator<Item = Usage>, ) -> Result<Vec<BudgetReservation>, BudgetExceeded>
Atomically reserves multiple independent budget shares.
Either every requested share is created in input order or none are.
§Errors
Returns BudgetExceeded without changing reservation state when the
complete batch would exceed a hard limit or overflow.
Trait Implementations§
Source§impl Clone for BudgetTracker
impl Clone for BudgetTracker
Source§fn clone(&self) -> BudgetTracker
fn clone(&self) -> BudgetTracker
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more