Skip to main content

WorkBudget

Struct WorkBudget 

Source
pub struct WorkBudget<'a> { /* private fields */ }
Expand description

A sticky, context-free local work counter.

Implementations§

Source§

impl WorkBudget<'static>

Source

pub const fn new(limit: usize) -> Self

Creates an independent local work slice.

Source§

impl<'a> WorkBudget<'a>

Source

pub fn with_session_work_scale(self, scale: NonZeroU64) -> Self

Set the session work owed by each local unit without changing this slice’s local ceiling. Attached children preserve the same scale.

Source

pub fn reserve_scratch( &self, bytes: u64, operation: &'static str, ) -> Result<WorkScratch<'a>, ResourceLimit>

Reserve temporary evaluator storage in the attached decode session. Independent slices retain fallible allocation without session charging.

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.

Source

pub fn exhausted(&self) -> bool

Returns whether this slice has refused a charge.

Source

pub fn exhaust(&self)

Marks this slice exhausted without consuming additional session work.

Source

pub fn remaining(&self) -> usize

Returns unconsumed work units.

Source

pub fn consumed(&self) -> usize

Returns charged work and the remainder forfeited by exhaustion.

Source

pub fn recursion_guard( &self, ) -> Result<WorkBudgetRecursionGuard<'_, 'a>, ResourceLimit>

Enters a session frame, or an independent frame with a 256-frame ceiling. Attached child slices share the active session depth.

Source

pub fn copy_recursion_path<T: Copy>( &self, path: &[T], ) -> Result<(Vec<T>, WorkScratch<'a>), ResourceLimit>

Copy the active cycle path and admit one new frame slot. The reservation covers the copied path until the frame leaves.

Source

pub fn child_slice(&self, limit: usize) -> WorkBudget<'static>

Creates an independent child slice capped by this budget’s remainder.

Source

pub fn session_child_slice(&self, limit: usize) -> WorkBudget<'_>

Creates a child slice capped by this budget’s remainder and attached to its session.

Source

pub fn consume_child( &self, child: &WorkBudget<'_>, ) -> Result<(), BudgetExhausted>

Charges this budget for work consumed by a child slice.

§Errors

BudgetExhausted when the child’s work is above this budget’s remainder. The budget marks itself exhausted in that case, so WorkBudget::exhausted answers true afterwards.

Trait Implementations§

Source§

impl<'a> Debug for WorkBudget<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for WorkBudget<'a>

§

impl<'a> !RefUnwindSafe for WorkBudget<'a>

§

impl<'a> !Send for WorkBudget<'a>

§

impl<'a> !Sync for WorkBudget<'a>

§

impl<'a> !UnwindSafe for WorkBudget<'a>

§

impl<'a> Unpin for WorkBudget<'a>

§

impl<'a> UnsafeUnpin for WorkBudget<'a>

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.