pub struct Context<'ctx, T = DefaultTypeSet>where
T: TypeSet,
T::Integer: Load<T> + Store<T>,
T::Float: Load<T> + Store<T>,
T::SignedInteger: Load<T> + Store<T>,{ /* private fields */ }Expand description
The expression context, which holds variables, functions, and other state needed for evaluation.
Implementations§
Source§impl<'ctx> Context<'ctx, DefaultTypeSet>
impl<'ctx> Context<'ctx, DefaultTypeSet>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new context with default types.
Source§impl<'ctx, T> Context<'ctx, T>where
T: TypeSet,
T::Integer: Load<T> + Store<T> + Integer,
T::Float: Load<T> + Store<T>,
T::SignedInteger: Load<T> + Store<T>,
<T::Integer as ValueType>::NegateOutput: Load<T> + Store<T>,
<T::SignedInteger as ValueType>::NegateOutput: Load<T> + Store<T>,
<T::Float as ValueType>::NegateOutput: Load<T> + Store<T>,
impl<'ctx, T> Context<'ctx, T>where
T: TypeSet,
T::Integer: Load<T> + Store<T> + Integer,
T::Float: Load<T> + Store<T>,
T::SignedInteger: Load<T> + Store<T>,
<T::Integer as ValueType>::NegateOutput: Load<T> + Store<T>,
<T::SignedInteger as ValueType>::NegateOutput: Load<T> + Store<T>,
<T::Float as ValueType>::NegateOutput: Load<T> + Store<T>,
Sourcepub fn new_with_types() -> Self
pub fn new_with_types() -> Self
Creates a new context. The type set must be specified when using this function.
use somni_expr::{Context, TypeSet32};
let mut ctx = Context::<TypeSet32>::new_with_types();Sourcepub fn evaluate_any<'s>(
&mut self,
expression: &'s str,
) -> Result<TypedValue<T>, ExpressionError<'s>>
pub fn evaluate_any<'s>( &mut self, expression: &'s str, ) -> Result<TypedValue<T>, ExpressionError<'s>>
Evaluates an expression and returns the result as a TypedValue<T>.
Sourcepub fn evaluate<'s, V>(
&'s mut self,
expression: &'s str,
) -> Result<V::Output<'s>, ExpressionError<'s>>where
V: Load<T>,
pub fn evaluate<'s, V>(
&'s mut self,
expression: &'s str,
) -> Result<V::Output<'s>, ExpressionError<'s>>where
V: Load<T>,
Evaluates an expression and returns the result as a specific value type.
This function will attempt to convert the result of the expression to the specified type V.
If the conversion fails, it will return an ExpressionError.
Sourcepub fn add_variable<V>(&mut self, name: &str, value: V)where
V: Store<T>,
pub fn add_variable<V>(&mut self, name: &str, value: V)where
V: Store<T>,
Defines a new variable in the context.
Sourcepub fn add_function<F, A>(&mut self, name: &str, func: F)where
F: DynFunction<A, T> + 'ctx,
pub fn add_function<F, A>(&mut self, name: &str, func: F)where
F: DynFunction<A, T> + 'ctx,
Adds a new function to the context.
Trait Implementations§
Source§impl<'ctx, T> Default for Context<'ctx, T>where
T: TypeSet + Default,
T::Integer: Load<T> + Store<T>,
T::Float: Load<T> + Store<T>,
T::SignedInteger: Load<T> + Store<T>,
impl<'ctx, T> Default for Context<'ctx, T>where
T: TypeSet + Default,
T::Integer: Load<T> + Store<T>,
T::Float: Load<T> + Store<T>,
T::SignedInteger: Load<T> + Store<T>,
Source§impl<T> ExprContext<T> for Context<'_, T>where
T: TypeSet,
T::Integer: Load<T> + Store<T> + Integer,
T::Float: Load<T> + Store<T>,
T::SignedInteger: Load<T> + Store<T>,
impl<T> ExprContext<T> for Context<'_, T>where
T: TypeSet,
T::Integer: Load<T> + Store<T> + Integer,
T::Float: Load<T> + Store<T>,
T::SignedInteger: Load<T> + Store<T>,
Source§fn intern_string(&mut self, s: &str) -> StringIndex
fn intern_string(&mut self, s: &str) -> StringIndex
Implements string interning.
Source§fn load_interned_string(&self, idx: StringIndex) -> &str
fn load_interned_string(&self, idx: StringIndex) -> &str
Loads an interned string.
Source§fn try_load_variable(&self, variable: &str) -> Option<TypedValue<T>>
fn try_load_variable(&self, variable: &str) -> Option<TypedValue<T>>
Attempts to load a variable from the context.
Source§fn address_of(&self, variable: &str) -> TypedValue<T>
fn address_of(&self, variable: &str) -> TypedValue<T>
Returns the address of a variable in the context.
Source§fn call_function(
&mut self,
function_name: &str,
args: &[TypedValue<T>],
) -> Result<TypedValue<T>, FunctionCallError>
fn call_function( &mut self, function_name: &str, args: &[TypedValue<T>], ) -> Result<TypedValue<T>, FunctionCallError>
Calls a function in the context.
Auto Trait Implementations§
impl<'ctx, T> Freeze for Context<'ctx, T>
impl<'ctx, T = DefaultTypeSet> !RefUnwindSafe for Context<'ctx, T>
impl<'ctx, T = DefaultTypeSet> !Send for Context<'ctx, T>
impl<'ctx, T = DefaultTypeSet> !Sync for Context<'ctx, T>
impl<'ctx, T> Unpin for Context<'ctx, T>
impl<'ctx, T = DefaultTypeSet> !UnwindSafe for Context<'ctx, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more