pub struct Evaluator<'a> { /* private fields */ }

Implementations

Adds a custom transform function This is meant as a way to allow consumers to add their own custom functionality to the expression language. Note that the name added here has to match with the name that the transform will have when it’s a part of the expression statement

Arguments:
  • name: The name of the transfrom
  • transform: The actual function. A closure the implements Fn(&serde_json::Value) -> Result<Value, anyhow::Error>
Example:
use jexl_eval::Evaluator;
use serde_json::{json as value, Value};

let mut evaluator = Evaluator::new().with_transform("lower", |v: &[Value]| {
   let s = v
           .first()
           .expect("Should have 1 argument!")
           .as_str()
           .expect("Should be a string!");
      Ok(value!(s.to_lowercase()))
 });

assert_eq!(evaluator.eval("'JOHN DOe'|lower").unwrap(), value!("john doe"))

Trait Implementations

Returns the “default value” for a type. Read more

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

Returns the argument unchanged.

Calls U::from(self).

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

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.