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 nodes in this tree.

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.

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.

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.

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.

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.

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.

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.

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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.