Struct evalexpr::Node [−][src]
pub struct Node { /* fields omitted */ }
Expand description
A node in the operator tree.
The operator tree is created by the crate-level build_operator_tree
method.
It can be evaluated for a given context with the Node::eval
method.
The advantage of constructing the operator tree separately from the actual evaluation is that it can be evaluated arbitrarily often with different contexts.
Examples
use evalexpr::*; let mut context = HashMapContext::new(); context.set_value("alpha".into(), 2.into()).unwrap(); // Do proper error handling here let node = build_operator_tree("1 + alpha").unwrap(); // Do proper error handling here assert_eq!(node.eval_with_context(&context), Ok(Value::from(3)));
Implementations
Returns an iterator over all identifiers in this expression. Each occurrence of an identifier is returned separately.
Examples
use evalexpr::*; let tree = build_operator_tree("a + b + c * f()").unwrap(); // Do proper error handling here let mut iter = tree.iter_identifiers(); assert_eq!(iter.next(), Some("a")); assert_eq!(iter.next(), Some("b")); assert_eq!(iter.next(), Some("c")); assert_eq!(iter.next(), Some("f")); assert_eq!(iter.next(), None);
Returns an iterator over all variable identifiers in this expression. Each occurrence of a variable identifier is returned separately.
Examples
use evalexpr::*; let tree = build_operator_tree("a + f(b + c)").unwrap(); // Do proper error handling here let mut iter = tree.iter_variable_identifiers(); assert_eq!(iter.next(), Some("a")); assert_eq!(iter.next(), Some("b")); assert_eq!(iter.next(), Some("c")); assert_eq!(iter.next(), None);
Returns an iterator over all function identifiers in this expression. Each occurrence of a function identifier is returned separately.
Examples
use evalexpr::*; let tree = build_operator_tree("a + f(b + c)").unwrap(); // Do proper error handling here let mut iter = tree.iter_function_identifiers(); assert_eq!(iter.next(), Some("f")); assert_eq!(iter.next(), None);
Evaluates the operator tree rooted at this node with the given context.
Fails, if one of the operators in the expression tree fails.
pub fn eval_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<Value>
pub fn eval_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<Value>
Evaluates the operator tree rooted at this node with the given mutable context.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a string with an the given context.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a float with an the given context.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into an integer with an the given context.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a float with an the given context. If the result of the expression is an integer, it is silently converted into a float.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a boolean with an the given context.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a tuple with an the given context.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into an empty value with an the given context.
Fails, if one of the operators in the expression tree fails.
pub fn eval_string_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<String>
pub fn eval_string_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<String>
Evaluates the operator tree rooted at this node into a string with an the given mutable context.
Fails, if one of the operators in the expression tree fails.
pub fn eval_float_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<FloatType>
pub fn eval_float_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<FloatType>
Evaluates the operator tree rooted at this node into a float with an the given mutable context.
Fails, if one of the operators in the expression tree fails.
pub fn eval_int_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<IntType>
pub fn eval_int_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<IntType>
Evaluates the operator tree rooted at this node into an integer with an the given mutable context.
Fails, if one of the operators in the expression tree fails.
pub fn eval_number_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<FloatType>
pub fn eval_number_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<FloatType>
Evaluates the operator tree rooted at this node into a float with an the given mutable context. If the result of the expression is an integer, it is silently converted into a float.
Fails, if one of the operators in the expression tree fails.
pub fn eval_boolean_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<bool>
pub fn eval_boolean_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<bool>
Evaluates the operator tree rooted at this node into a boolean with an the given mutable context.
Fails, if one of the operators in the expression tree fails.
pub fn eval_tuple_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<TupleType>
pub fn eval_tuple_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<TupleType>
Evaluates the operator tree rooted at this node into a tuple with an the given mutable context.
Fails, if one of the operators in the expression tree fails.
pub fn eval_empty_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<EmptyType>
pub fn eval_empty_with_context_mut<C: ContextWithMutableVariables>(
&self,
context: &mut C
) -> EvalexprResult<EmptyType>
Evaluates the operator tree rooted at this node into an empty value with an the given mutable context.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a string.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a float.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into an integer.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a float. If the result of the expression is an integer, it is silently converted into a float.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a boolean.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into a tuple.
Fails, if one of the operators in the expression tree fails.
Evaluates the operator tree rooted at this node into an empty value.
Fails, if one of the operators in the expression tree fails.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Node
impl UnwindSafe for Node
Blanket Implementations
Mutably borrows from an owned value. Read more