Evaluator

Struct Evaluator 

Source
pub struct Evaluator { /* private fields */ }

Implementations§

Source§

impl Evaluator

Source

pub fn new( context: HashMap<String, Value>, custom_functions: HashMap<String, Arc<dyn CustomFunction>>, ) -> Self

Examples found in repository?
examples/basic.rs (lines 15-20)
9fn main() -> Result<(), Box<dyn Error>> {
10    #[cfg(feature = "logging")]
11    let logger = scribe_rust::Logger::default();
12
13    let mut ctx = HashMap::new();
14    ctx.insert("x".to_string(), serde_json::Value::Number(5.into()));
15    let engine = exprimo::Evaluator::new(
16        ctx,
17        HashMap::new(), // custom_functions
18        #[cfg(feature = "logging")]
19        logger,
20    );
21
22    let result = engine.evaluate("x == 5")?;
23
24    println!("x = {}", result);
25
26    Ok(())
27}
More examples
Hide additional examples
examples/payload.rs (lines 94-99)
87fn main() -> Result<(), Box<dyn Error>> {
88    #[cfg(feature = "logging")]
89    let logger = scribe_rust::Logger::default();
90
91    let mut ctx = HashMap::new();
92
93    add_context("send_email", r#"{"status": "success"}"#, &mut ctx);
94    let engine = exprimo::Evaluator::new(
95        to_json(&ctx),
96        HashMap::new(), // custom_functions
97        #[cfg(feature = "logging")]
98        logger,
99    );
100
101    let expr = r#"send_email.status === 'success' "#;
102
103    let result = engine.evaluate(expr)?;
104
105    println!("send_email.status === 'success' => {}", result);
106
107    Ok(())
108}
Source

pub fn evaluate(&self, expression: &str) -> Result<Value, EvaluationError>

Examples found in repository?
examples/basic.rs (line 22)
9fn main() -> Result<(), Box<dyn Error>> {
10    #[cfg(feature = "logging")]
11    let logger = scribe_rust::Logger::default();
12
13    let mut ctx = HashMap::new();
14    ctx.insert("x".to_string(), serde_json::Value::Number(5.into()));
15    let engine = exprimo::Evaluator::new(
16        ctx,
17        HashMap::new(), // custom_functions
18        #[cfg(feature = "logging")]
19        logger,
20    );
21
22    let result = engine.evaluate("x == 5")?;
23
24    println!("x = {}", result);
25
26    Ok(())
27}
More examples
Hide additional examples
examples/payload.rs (line 103)
87fn main() -> Result<(), Box<dyn Error>> {
88    #[cfg(feature = "logging")]
89    let logger = scribe_rust::Logger::default();
90
91    let mut ctx = HashMap::new();
92
93    add_context("send_email", r#"{"status": "success"}"#, &mut ctx);
94    let engine = exprimo::Evaluator::new(
95        to_json(&ctx),
96        HashMap::new(), // custom_functions
97        #[cfg(feature = "logging")]
98        logger,
99    );
100
101    let expr = r#"send_email.status === 'success' "#;
102
103    let result = engine.evaluate(expr)?;
104
105    println!("send_email.status === 'success' => {}", result);
106
107    Ok(())
108}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Erasable for T

Source§

const ACK_1_1_0: bool = true

Whether this implementor has acknowledged the 1.1.0 update to unerase’s documented implementation requirements. Read more
Source§

unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>

Unerase this erased pointer. Read more
Source§

fn erase(this: NonNull<Self>) -> NonNull<Erased>

Turn this erasable pointer into an erased pointer. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.