Skip to main content

FoldOptions

Struct FoldOptions 

Source
pub struct FoldOptions<'a> {
Show 14 fields pub op: IndexMap<String, Option<OpDef>>, pub evaluate: FoldEvaluate<'a>, pub inherit: Option<Inherit<'a>>, pub recognise: Option<Recognise<'a>>, pub k: Value, pub doc: String, pub load: Option<Load<'a>>, pub cycle: FoldCycle, pub tokens: bool, pub positions: Option<Positions<'a>>, pub max_depth: usize, pub max_stack: usize, pub budget: Option<FoldBudget<'a>>, pub report: Option<Box<dyn Fn(FoldReport) + 'a>>,
}
Expand description

The options of one fold. Only evaluate is required; build with FoldOptions::new and the with_ methods.

The callbacks are plain closures that may borrow from the caller’s scope, for the life 'a of the options: a fold runs to completion inside the call.

Fields§

§op: IndexMap<String, Option<OpDef>>

The operator table; only its key operators matter to a fold. The same table the plugin was given can be passed as it is.

§evaluate: FoldEvaluate<'a>§inherit: Option<Inherit<'a>>§recognise: Option<Recognise<'a>>§k: Value

The starting bag of every document’s root. An empty map by default.

§doc: String

The key of the document being folded. Empty by default.

§load: Option<Load<'a>>§cycle: FoldCycle§tokens: bool

Reduce token operator nodes met in the walk through evaluate too, so one fold handles + and $ref. On by default. A token operator is recognised only on a LIVE expression node, inside crate::parse_scope: see fold.

§positions: Option<Positions<'a>>§max_depth: usize

How deep the walk may go, nesting and reference hops counted together. 1000 by default.

§max_stack: usize

How much stack, in bytes, the fold may use, measured from the outermost fold running on the thread: FOLD_MAX_STACK, a megabyte, by default. Past it the fold fails with FOLD_DEPTH rather than overflow the stack, which would end the process. A level of nesting costs no stack, since the walk over containers is iterative; each reference hop does, since it re-enters the fold through the resolver. Raise it only on a thread known to have more than twice as much stack.

§budget: Option<FoldBudget<'a>>

How much work the fold may do, and a check that can cancel it. None by default: no bound and no check.

§report: Option<Box<dyn Fn(FoldReport) + 'a>>

Called once with the report when the fold succeeds.

Implementations§

Source§

impl<'a> FoldOptions<'a>

Source

pub fn new( evaluate: impl Fn(&Site<'_>, &Op, &[Value]) -> Result<Value, TabnasError> + 'a, ) -> Self

Options with the given resolver and every default.

Source

pub fn with_op(self, name: impl Into<String>, def: OpDef) -> Self

Add or replace one operator definition.

Source

pub fn with_ops(self, op: IndexMap<String, Option<OpDef>>) -> Self

Use a whole operator table, such as the one an ExprOptions carries.

Source

pub fn with_inherit( self, inherit: impl Fn(&Site<'_>, &Value, &Value) -> Result<Value, TabnasError> + 'a, ) -> Self

Source

pub fn with_recognise( self, recognise: impl Fn(&Site<'_>, &Op) -> Result<bool, TabnasError> + 'a, ) -> Self

Source

pub fn with_k(self, k: Value) -> Self

Source

pub fn with_doc(self, doc: impl Into<String>) -> Self

Source

pub fn with_load( self, load: impl Fn(&str, &Site<'_>) -> Result<Option<Value>, TabnasError> + 'a, ) -> Self

Source

pub fn with_cycle(self, cycle: FoldCycle) -> Self

Source

pub fn with_tokens(self, tokens: bool) -> Self

Source

pub fn with_positions( self, positions: impl Fn(&Value) -> Option<Token> + 'a, ) -> Self

Source

pub fn with_max_depth(self, max_depth: usize) -> Self

Source

pub fn with_max_stack(self, max_stack: usize) -> Self

Source

pub fn with_budget(self, budget: FoldBudget<'a>) -> Self

Source

pub fn with_report(self, report: impl Fn(FoldReport) + 'a) -> Self

Trait Implementations§

Source§

impl Debug for FoldOptions<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'a> Forget for FoldOptions<'a>

§

impl<'a> Freeze for FoldOptions<'a>

§

impl<'a> Move for FoldOptions<'a>

§

impl<'a> Unpin for FoldOptions<'a>

§

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