pub struct Evaluator<'a> { /* private fields */ }
Implementations§
Source§impl<'a> Evaluator<'a>
impl<'a> Evaluator<'a>
pub fn new() -> Self
Sourcepub fn with_transform<F>(self, name: &str, transform: F) -> Self
pub fn with_transform<F>(self, name: &str, transform: F) -> Self
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 transfromtransform
: 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>
pub fn eval_in_context<'b, T: Serialize>( &self, input: &'b str, context: T, ) -> Result<'b, Value>
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Evaluator<'a>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more