Skip to main content

EvalBuilder

Struct EvalBuilder 

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

A builder bound to a ParsedExpression that defers choosing symbol tables until evaluate is called.

Obtained from parsed.with_*(...) on a ParsedExpression. Every with_* method is chainable. The terminal evaluate(&symtabs) and evaluate_with_metrics(&symtabs) methods build an internal evaluator from the captured configuration and run it.

use openjd_expr::{ExprValue, ParsedExpression, PathFormat, SymbolTable};

let parsed = ParsedExpression::new("Param.Frame * 2").unwrap();
let mut st = SymbolTable::new();
st.set("Param.Frame", 5).unwrap();

let value = parsed
    .with_path_format(PathFormat::Posix)
    .with_memory_limit(50_000_000)
    .evaluate(&[&st])
    .unwrap();
assert_eq!(value, ExprValue::Int(10));

Implementations§

Source§

impl<'a> EvalBuilder<'a>

Source

pub fn with_library(self, library: &'a FunctionLibrary) -> Self

Use the given function library instead of the default one.

Source

pub fn with_memory_limit(self, limit: usize) -> Self

Cap evaluation memory (bytes). Default: DEFAULT_MEMORY_LIMIT.

Source

pub fn with_operation_limit(self, limit: usize) -> Self

Cap evaluation operations. Default: DEFAULT_OPERATION_LIMIT.

Source

pub fn with_path_format(self, format: PathFormat) -> Self

Normalize path values according to format. Default: host-native.

Source

pub fn with_target_type(self, target_type: &'a ExprType) -> Self

Coerce the final value toward target_type. Default: no coercion.

Source

pub fn evaluate( self, symtabs: &'a [&'a SymbolTable], ) -> Result<ExprValue, ExpressionError>

Evaluate against the supplied symbol tables and return the resulting value.

Source

pub fn evaluate_with_metrics( self, symtabs: &'a [&'a SymbolTable], ) -> Result<EvalResult, ExpressionError>

Evaluate and return the value alongside resource-usage metrics.

Auto Trait Implementations§

§

impl<'a> Freeze for EvalBuilder<'a>

§

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

§

impl<'a> Send for EvalBuilder<'a>

§

impl<'a> Sync for EvalBuilder<'a>

§

impl<'a> Unpin for EvalBuilder<'a>

§

impl<'a> UnsafeUnpin for EvalBuilder<'a>

§

impl<'a> !UnwindSafe for EvalBuilder<'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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.