Skip to main content

WorkBudget

Struct WorkBudget 

Source
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

Source

pub const RECURSION_DEPTH: usize = 256

The recursion ceiling of WorkBudget::recursion_guard.

Source

pub fn new(limit: usize) -> Self

Creates a work counter with limit units.

Source

pub fn charge(&self) -> bool

Charges one work unit, returning false after exhaustion.

Source

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.

Source

pub fn exhausted(&self) -> bool

Returns whether this counter has refused a charge.

Source

pub fn exhaust(&self)

Marks this counter exhausted. The counters it was drawn from are not.

Source

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.

Source

pub fn consumed(&self) -> usize

Returns work charged to this counter and the remainder forfeited by exhaustion.

Source

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.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for WorkBudget

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.