Skip to main content

EvalCtx

Struct EvalCtx 

Source
pub struct EvalCtx<'a> {
    pub note: &'a Note,
    pub corpus: &'a Corpus,
    pub this: Option<&'a Note>,
    pub formulas: &'a BTreeMap<String, Expr>,
    /* private fields */
}
Expand description

Everything an expression needs to evaluate: the note it’s evaluated against, the whole corpus (for backlinks/link resolution), the base’s formula definitions, and an optional this context note (the note a base is embedded in). Formula evaluation is memoized per note with a cycle guard.

Fields§

§note: &'a Note§corpus: &'a Corpus§this: Option<&'a Note>§formulas: &'a BTreeMap<String, Expr>

Formula name → parsed expression (shared across the whole base).

Implementations§

Source§

impl<'a> EvalCtx<'a>

Source

pub fn new( note: &'a Note, corpus: &'a Corpus, formulas: &'a BTreeMap<String, Expr>, ) -> Self

Source

pub fn with_this(self, this: Option<&'a Note>) -> Self

Source

pub fn eval_formula(&self, name: &str) -> Value

Evaluate a named formula against this context’s note, memoized, with a cycle guard (a self-referential formula yields Null).

Source

pub fn eval(&self, expr: &Expr) -> Value

Evaluate an expression to a value. Depth-guarded: a pathologically deep AST resolves to Null past MAX_EVAL_DEPTH rather than overflowing the stack.

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<'a> Send for EvalCtx<'a>

§

impl<'a> Unpin for EvalCtx<'a>

§

impl<'a> UnsafeUnpin for EvalCtx<'a>

§

impl<'a> UnwindSafe for EvalCtx<'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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.