Skip to main content

Expr

Struct Expr 

Source
pub struct Expr<T> { /* private fields */ }
Expand description

A parse-checked Jetro expression with a phantom output type.

The phantom T captures the caller’s intent about the result shape and is used by typed accessors (e.g. Bucket::get_as) to drive serde deserialisation. It is not statically verified — constructing an Expr<u64> from an expression that yields a string is possible; the mismatch surfaces at evaluation time as a deserialisation error.

Implementations§

Source§

impl<T> Expr<T>

Source

pub fn new<S: Into<String>>(src: S) -> Result<Self, Error>

Parse and wrap src. Returns Error::Parse if the expression is not syntactically valid.

Source

pub fn as_str(&self) -> &str

Raw source text — useful for storing in an [ExprBucket] or for debugging.

Source

pub fn into_string(self) -> String

Discard the phantom output type. Rarely needed; cast::<U> is usually what callers want.

Source

pub fn cast<U>(self) -> Expr<U>

Re-tag the expression with a different phantom output type. No reparse; cheap.

Source§

impl<T: DeserializeOwned> Expr<T>

Source

pub fn eval(&self, doc: &Value) -> Result<T, Error>

Evaluate self against doc, returning a typed value.

Goes through a fresh VM — for repeated evaluations prefer Expr::eval_with so caches accumulate.

Source

pub fn eval_with(&self, vm: &mut VM, doc: &Value) -> Result<T, Error>

Evaluate with a caller-supplied VM so its compile and resolution caches are shared across calls.

Source§

impl Expr<Value>

Source

pub fn eval_raw(&self, doc: &Value) -> Result<Value, Error>

Evaluate and return the raw Value without deserialisation.

Trait Implementations§

Source§

impl<T> AsRef<str> for Expr<T>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, U> BitOr<Expr<U>> for Expr<T>

a | b → expression source "(a) | (b)". The resulting type is Expr<U> since the right-hand side determines the output shape.

Source§

type Output = Expr<U>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: Expr<U>) -> Expr<U>

Performs the | operation. Read more
Source§

impl<T: Clone> Clone for Expr<T>

Source§

fn clone(&self) -> Expr<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for Expr<T>

Source§

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

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

impl<T> Display for Expr<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Expr<T>

§

impl<T> RefUnwindSafe for Expr<T>

§

impl<T> Send for Expr<T>

§

impl<T> Sync for Expr<T>

§

impl<T> Unpin for Expr<T>

§

impl<T> UnsafeUnpin for Expr<T>

§

impl<T> UnwindSafe for Expr<T>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.