Skip to main content

FoldBudget

Struct FoldBudget 

Source
pub struct FoldBudget<'a> {
    pub steps: usize,
    pub check_every_n: usize,
    pub on_check: Option<Box<dyn Fn(usize) -> bool + 'a>>,
}
Expand description

A bound on a fold’s work, and a way to stop it.

One step is one container the fold starts to fold (a map, a list or an operator node; a location already folded costs nothing), or one call a resolver makes to Site::at, Site::written or Site::locate, whatever it finds. Nothing else is a step: not Site::plain, not inherit, not evaluate, not loading a document. One count spans every document a fold loads.

Past steps the fold fails with FOLD_BUDGET. With check_every_n and on_check both set, on_check is called at every Nth step with the number taken so far, and a false return fails the fold with FOLD_CANCEL: a host keeps a deadline there, or reads a flag another thread sets. At one step the bound is tried before the check. Off by default, as the engine’s own parse budget is.

Fields§

§steps: usize

The most steps a fold may take; 0 sets no bound.

§check_every_n: usize

Call on_check at every Nth step; 0 turns the check off.

§on_check: Option<Box<dyn Fn(usize) -> bool + 'a>>

Given the number of steps taken so far; false cancels the fold.

Implementations§

Source§

impl<'a> FoldBudget<'a>

Source

pub fn new(steps: usize) -> Self

A bound of steps and no check.

Source

pub fn with_check( self, check_every_n: usize, on_check: impl Fn(usize) -> bool + 'a, ) -> Self

Call on_check at every check_every_nth step.

Trait Implementations§

Source§

impl Debug for FoldBudget<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for FoldBudget<'a>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'a> Forget for FoldBudget<'a>

§

impl<'a> Freeze for FoldBudget<'a>

§

impl<'a> Move for FoldBudget<'a>

§

impl<'a> Unpin for FoldBudget<'a>

§

impl<'a> UnsafeUnpin for FoldBudget<'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.