[−][src]Struct jexl_eval::Evaluator
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]
F: Fn(&[Value]) -> Result<'_, Value, Error> + 'a,
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>
[src]
pub fn eval_in_context<'b, T: Serialize>(
&self,
input: &'b str,
context: T
) -> Result<'b, Value>
[src]
&self,
input: &'b str,
context: T
) -> Result<'b, Value>
Trait Implementations
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,