Crate metrics_evaluation

Source
Expand description

This crate provides a small-footprint solution to evaluate comparisons, expressed as text, with a dynamically value-lookup.

The comparisons can be written like normal rust-code. For example:

foo + 2 > 2 && bar != 42 || (baz == 47111 && barg * 42 <= 99) && foo >= bar - 5.

The only limitation at the moment is that you currently have to use a variable-name on the left-hand (WIP). Left-Hand values are not supported yet.

Comparisons can be made against any Value-Type implemented:

Value-Lookup is made through a given Resolver-trait internally so you are open to use what ever you like in the background to resolve variable-names to their value-representation.

If you want to use an async resolver (see AsyncResolver), you have to enable the async feature.

For laziness there is a MapResolver which implements Resolver and can be made From any std::collections::HashMap that contain a Key which is AsRef<str> and values which can be made Value::From.

For the ease of use, an crate::evaluate function is implemented which just takes a string and compares using a given resolver.

To have a more performant usage of this crate, use crate::parse_tree which produces a pre-parsed Sequence once. This Sequence can then be used in subsequent calls to crate::solve_tree to evalaute the Sequence with current variable-values over and over again.

Re-exports§

pub use calculate::Arithmetic;
pub use calculate::Calculateable;
pub use calculate::Calculation;
pub use expr_parser::parse_tree;
pub use mapresolver::MapResolver;
pub use resolver::Resolver;
pub use sequence::Sequence;
pub use solver::solve_tree;
pub use value::Value;

Modules§

calculate
Compute arithmetics on Values
compare
Compare Value against Value
expr_parser
Parser to generate Sequence from a given text
mapresolver
Helper-Object to use std::collections::HashMap as Resolver
resolver
Resolves name to Value
sequence
Sequence of comparisons
solver
Solves Sequence
value
A generic value

Functions§

evaluate
Evaluate string-sequence with the given Resolver resolver to a final bool-result. This always parses the sequence-string, generates a Sequence and evaluats it using the given Resolver. Use this if the input-sequence is changing on the same logic. To have a better performing solution where input-sequences do not change and where you just want to check a given logic against changing metrics, save the output of parse_tree and throw it towards a value-changing Resolver in a solve_tree when needed.