Skip to main content

ExprEngine

Struct ExprEngine 

Source
pub struct ExprEngine { /* private fields */ }
Expand description

Compiles and evaluates the JSONLogic a definition is written in.

Cheap to clone: a clone shares the datalogic engine, the operator table and the secrets.

Implementations§

Source§

impl ExprEngine

Source

pub fn interpolated(&self, raw: &Value) -> Result<Interpolated, Vec<Issue>>

Compiles a document of var holes in otherwise literal data.

Advisories and Defects (a payload hole, an operator left as data) are dropped on Ok; a config field compiled through ConfigField is the way to get them.

§Errors

Every issue, when any is Rejected.

Source§

impl ExprEngine

Source

pub fn builder() -> ExprEngineBuilder

Starts a builder.

Source

pub fn operators(&self) -> &[Operator]

Every operator this engine evaluates: the datalogic built-ins its selected families enable, then the host’s operators in registration order, then secret.

Source

pub fn secrets(&self) -> &Secrets

The secrets the secret operator reads.

Source

pub fn escape(&self) -> char

The template-key escape: $.

Source

pub fn compile<T: FromValue>(&self, raw: &Value) -> Result<Expr<T>>

Compiles raw. An expression that reads nothing is evaluated once, here, and kept as its T.

§Errors

ErrorKind::Compile when datalogic refuses the expression; ErrorKind::Eval when evaluating a constant at fold time fails; ErrorKind::Config when a folded constant is not a T.

Source

pub fn eval<'e, 'r, T: FromValue>( &self, expr: &'e Expr<T>, root: impl EvalRoot<'r>, ) -> Result<Evaluated<T::Out<'e>>>

Evaluates expr against root, an object holding the three context roots, as an OwnedDataValue or a serde_json::Value (EvalRoot). A folded constant is lent from expr and takes no arena.

§Errors

ErrorKind::Budget when the operation ceiling is exceeded; ErrorKind::Eval for any other failure, including a result that is not a T.

Trait Implementations§

Source§

impl Clone for ExprEngine

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExprEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ExprEngine

Source§

fn default() -> Self

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.