pub struct WorkBudget { /* private fields */ }Expand description
A local work counter for one bounded search or iteration.
Exhaustion is sticky: once a charge is refused, every later charge is refused. A caller that runs out skips the step it bounds and reports the skip; exhaustion never refuses the decode session.
Implementations§
Source§impl WorkBudget
impl WorkBudget
Sourcepub const RECURSION_DEPTH: usize = 256
pub const RECURSION_DEPTH: usize = 256
The recursion ceiling of WorkBudget::recursion_guard.
Sourcepub fn charge_by(&self, work: usize) -> bool
pub fn charge_by(&self, work: usize) -> bool
Charges several work units, with sticky exhaustion on refusal.
A charging slice also charges every counter it was drawn from. A charge that one of them cannot pay exhausts this counter only.
Sourcepub fn remaining(&self) -> usize
pub fn remaining(&self) -> usize
Returns the work units a charge can still use: the smallest remainder of this counter and every counter it was drawn from.
Sourcepub fn consumed(&self) -> usize
pub fn consumed(&self) -> usize
Returns work charged to this counter and the remainder forfeited by exhaustion.
Sourcepub fn recursion_guard(
&self,
) -> Result<WorkBudgetRecursionGuard<'_>, BudgetExhausted>
pub fn recursion_guard( &self, ) -> Result<WorkBudgetRecursionGuard<'_>, BudgetExhausted>
Enters one recursive frame, refusing past WorkBudget::RECURSION_DEPTH.
The refusal exhausts the counter; it does not touch a decode session.
Sourcepub fn child_slice(&self, limit: usize) -> WorkBudget
pub fn child_slice(&self, limit: usize) -> WorkBudget
Creates a child counter capped by this counter’s remainder.
The child’s charges do not reach this counter until
WorkBudget::consume_child transfers them.
Sourcepub fn charging_slice(&self, limit: usize) -> WorkBudget
pub fn charging_slice(&self, limit: usize) -> WorkBudget
Creates a child counter of at most limit units whose every charge is
also charged to this counter, so the work below a counter never
exceeds its limit.
Exhausting the child, by its own limit or by an ancestor that cannot pay, leaves this counter usable.
Sourcepub fn consume_child(&self, child: &WorkBudget) -> Result<(), BudgetExhausted>
pub fn consume_child(&self, child: &WorkBudget) -> Result<(), BudgetExhausted>
Charges this counter for work consumed by a child counter.
§Errors
BudgetExhausted when the child’s work is above this counter’s
remainder. The counter marks itself exhausted in that case.