Struct exmex::prelude::FlatEx [−][src]
pub struct FlatEx<T, OF = FloatOpsFactory<T>, LM = NumberMatcher> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral, { /* fields omitted */ }
Expand description
This is the core data type representing a flattened expression and the result of
parsing a string. We use flattened expressions to make efficient evaluation possible.
Simplified, a flat expression consists of a SmallVec
of nodes and a SmallVec
of operators that are applied
to the nodes in an order following operator priorities.
Creation of expressions is possible with the function parse
which is equivalent to
FlatEx::from_str
.
use exmex::prelude::*;
// create an expression by parsing a string
let expr = FlatEx::<f32>::from_str("sin(1+y)*x")?;
assert!((expr.eval(&[1.5, 2.0])? - (1.0 + 2.0 as f32).sin() * 1.5).abs() < 1e-6);
The argument &[1.5, 2.0]
in the call of eval
specifies the
variable values in the alphabetical order of the variable names.
In this example, we want to evaluate the expression for the varibale values x=2.0
and y=1.5
.
Implementations
impl<T, OF, LMF> FlatEx<T, OF, LMF> where
T: DataType,
OF: MakeOperators<T>,
LMF: MatchLiteral,
impl<T, OF, LMF> FlatEx<T, OF, LMF> where
T: DataType,
OF: MakeOperators<T>,
LMF: MatchLiteral,
Trait Implementations
impl<T: Clone, OF: Clone, LM: Clone> Clone for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<T: Clone, OF: Clone, LM: Clone> Clone for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<T: Debug, OF: Debug, LM: Debug> Debug for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<T: Debug, OF: Debug, LM: Debug> Debug for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<'de, T: DataType + 'de, OF: MakeOperators<T>, LMF: MatchLiteral> Deserialize<'de> for FlatEx<T, OF, LMF> where
<T as FromStr>::Err: Debug,
impl<'de, T: DataType + 'de, OF: MakeOperators<T>, LMF: MatchLiteral> Deserialize<'de> for FlatEx<T, OF, LMF> where
<T as FromStr>::Err: Debug,
Deserialize this value from the given Serde deserializer. Read more
impl<T, OF, LM> Differentiate<T> for FlatEx<T, OF, LM> where
T: DataType,
OF: MakeOperators<T> + Debug,
LM: MatchLiteral + Debug,
impl<T, OF, LM> Differentiate<T> for FlatEx<T, OF, LM> where
T: DataType,
OF: MakeOperators<T> + Debug,
LM: MatchLiteral + Debug,
impl<T, OF, LMF> Display for FlatEx<T, OF, LMF> where
T: DataType,
OF: MakeOperators<T>,
LMF: MatchLiteral,
impl<T, OF, LMF> Display for FlatEx<T, OF, LMF> where
T: DataType,
OF: MakeOperators<T>,
LMF: MatchLiteral,
The expression is displayed as a string created by unparse
.
impl<T, OF, LM> Express<T> for FlatEx<T, OF, LM> where
T: DataType,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<T, OF, LM> Express<T> for FlatEx<T, OF, LM> where
T: DataType,
OF: MakeOperators<T>,
LM: MatchLiteral,
type LiteralMatcher = LM
type OperatorFactory = OF
Evaluates an expression with the given variable values and returns the computed result. Read more
Creates an expression string that corresponds to the FlatEx
instance. Read more
impl<T, OF, LMF> FromStr for FlatEx<T, OF, LMF> where
T: DataType,
OF: MakeOperators<T>,
LMF: MatchLiteral,
<T as FromStr>::Err: Debug,
impl<T, OF, LMF> FromStr for FlatEx<T, OF, LMF> where
T: DataType,
OF: MakeOperators<T>,
LMF: MatchLiteral,
<T as FromStr>::Err: Debug,
impl<T: Ord, OF: Ord, LM: Ord> Ord for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<T: Ord, OF: Ord, LM: Ord> Ord for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<T: PartialOrd, OF: PartialOrd, LM: PartialOrd> PartialOrd<FlatEx<T, OF, LM>> for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<T: PartialOrd, OF: PartialOrd, LM: PartialOrd> PartialOrd<FlatEx<T, OF, LM>> for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
impl<'de, T: DataType, OF: MakeOperators<T>, LMF: MatchLiteral> Serialize for FlatEx<T, OF, LMF>
impl<'de, T: DataType, OF: MakeOperators<T>, LMF: MatchLiteral> Serialize for FlatEx<T, OF, LMF>
impl<T: Eq, OF: Eq, LM: Eq> Eq for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<T, OF, LM> StructuralEq for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
impl<T, OF, LM> StructuralPartialEq for FlatEx<T, OF, LM> where
T: Debug + Clone,
OF: MakeOperators<T>,
LM: MatchLiteral,
Auto Trait Implementations
impl<T, OF, LM> RefUnwindSafe for FlatEx<T, OF, LM> where
LM: RefUnwindSafe,
OF: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, OF, LM> UnwindSafe for FlatEx<T, OF, LM> where
LM: UnwindSafe,
OF: UnwindSafe,
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more