[][src]Struct jexl_eval::Evaluator

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

Implementations

impl<'a> Evaluator<'a>[src]

pub fn new() -> Self[src]

pub fn with_transform<F>(self, name: &str, transform: F) -> Self where
    F: Fn(&[Value]) -> Result<'_, Value, Error> + 'a, 
[src]

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"))

pub fn eval<'b>(&self, input: &'b str) -> Result<'b, Value>[src]

pub fn eval_in_context<'b, T: Serialize>(
    &self,
    input: &'b str,
    context: T
) -> Result<'b, Value>
[src]

Trait Implementations

impl<'a> Default for Evaluator<'a>[src]

Auto Trait Implementations

impl<'a> !RefUnwindSafe for Evaluator<'a>

impl<'a> !Send for Evaluator<'a>

impl<'a> !Sync for Evaluator<'a>

impl<'a> Unpin for Evaluator<'a>

impl<'a> !UnwindSafe for Evaluator<'a>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.