Skip to main content

Expr

Struct Expr 

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

A typed expression in the Toasty query language.

Expr<T> wraps an untyped AST expression node and tags it with a Rust type T that represents the expression’s value type. Common instantiations:

  • Expr<bool> — a boolean filter expression (comparisons, and, or, not).
  • Expr<String>, Expr<i64>, etc. — scalar value expressions.
  • Expr<Option<T>> — a nullable expression with is_none and is_some helpers.
  • Expr<List<T>> — a list expression (see Expr::list).

Expressions are built from [Path] comparisons, literal values via IntoExpr, and combinators like and and or.

Implementations§

Source§

impl<T> Expr<T>

Source

pub fn from_untyped(untyped: impl Into<Expr>) -> Expr<T>

Wrap a raw untyped expression, tagging it with type T.

§Examples
let expr = Expr::<i64>::from_untyped(core_stmt::Expr::Value(
    core_stmt::Value::from(42_i64),
));
Source

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

Re-tag this expression with a different type U.

This performs no runtime conversion — the underlying AST node is unchanged. Use this when the type system needs a different type tag but the expression itself is compatible (e.g., widening Expr<T> to Expr<Option<T>>).

§Examples
let expr: Expr<i64> = 42_i64.into_expr();
let optional: Expr<Option<i64>> = expr.cast();
Source

pub fn eq(self, rhs: impl IntoExpr<T>) -> Expr<bool>

Test whether this expression equals rhs.

Source

pub fn ne(self, rhs: impl IntoExpr<T>) -> Expr<bool>

Test whether this expression does not equal rhs.

Source

pub fn gt(self, rhs: impl IntoExpr<T>) -> Expr<bool>

Test whether this expression is greater than rhs.

Source

pub fn ge(self, rhs: impl IntoExpr<T>) -> Expr<bool>

Test whether this expression is greater than or equal to rhs.

Source

pub fn lt(self, rhs: impl IntoExpr<T>) -> Expr<bool>

Test whether this expression is less than rhs.

Source

pub fn le(self, rhs: impl IntoExpr<T>) -> Expr<bool>

Test whether this expression is less than or equal to rhs.

Source§

impl<T> Expr<List<T>>

Source

pub fn list<I>(items: impl IntoIterator<Item = I>) -> Expr<List<T>>
where I: IntoExpr<T>,

Build a list expression from an iterator of items.

Each item is converted to an Expr<T> via IntoExpr. The resulting expression represents a literal list value.

§Examples
let ids = Expr::<List<i64>>::list([1_i64, 2, 3]);
Source§

impl Expr<bool>

Source

pub fn and(self, rhs: impl IntoExpr<bool>) -> Expr<bool>

Combine two boolean expressions with logical AND.

§Examples
let filter = User::fields().name().eq("Alice")
    .and(User::fields().age().gt(18));
Source

pub fn and_all<E>(exprs: impl IntoIterator<Item = E>) -> Expr<bool>
where E: IntoExpr<bool>,

Combine an iterator of boolean expressions with logical AND.

Returns true (no filter) when the iterator is empty.

§Examples
use toasty::stmt::Expr;

let conditions = vec![
    User::fields().name().eq("Alice"),
    User::fields().age().gt(18),
];
let combined = Expr::and_all(conditions);
Source

pub fn or(self, rhs: impl IntoExpr<bool>) -> Expr<bool>

Combine two boolean expressions with logical OR.

§Examples
let filter = User::fields().name().eq("Alice")
    .or(User::fields().name().eq("Bob"));
Source

pub fn not(self) -> Expr<bool>

Negate this boolean expression.

Equivalent to the ! operator (which is also implemented via Not).

§Examples
let not_alice = User::fields().name().eq("Alice").not();
Source

pub fn in_list<L, R, T>(lhs: L, rhs: R) -> Expr<bool>
where L: IntoExpr<T>, R: IntoExpr<List<T>>,

Test whether lhs is contained in rhs.

This is the associated-function form of in_list. Both single values and tuples (composite keys) are supported.

§Examples
use toasty::stmt::Expr;

let filter = Expr::in_list(User::fields().id(), [1_i64, 2, 3]);
Source§

impl<T> Expr<Option<T>>

Source

pub fn is_none(self) -> Expr<bool>

Test whether this optional expression is NULL.

§Examples
let expr: Expr<Option<i64>> = None::<i64>.into_expr();
let _is_null: Expr<bool> = expr.is_none();
Source

pub fn is_some(self) -> Expr<bool>

Test whether this optional expression is not NULL.

§Examples
let expr: Expr<Option<i64>> = Some(42_i64).into_expr();
let _is_not_null: Expr<bool> = expr.is_some();

Trait Implementations§

Source§

impl<T> Assign<T> for Expr<T>

Source§

fn into_assignment(self) -> Assignment<T>

Convert into an Assignment<T> value.
Source§

fn assign(self, assignments: &mut Assignments, projection: Projection)
where Self: Sized,

Record one or more assignments into the given [Assignments] map at the specified projection.
Source§

impl<T> Clone for Expr<T>

Source§

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

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<T> Debug for Expr<T>
where T: Debug,

Source§

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

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

impl<T> From<Insert<T>> for Expr<T>

Source§

fn from(value: Insert<T>) -> Expr<T>

Converts to this type from the input type.
Source§

impl<T> From<Insert<T>> for Expr<Option<T>>

Source§

fn from(value: Insert<T>) -> Expr<Option<T>>

Converts to this type from the input type.
Source§

impl<T> IntoExpr<T> for Expr<T>

Source§

fn into_expr(self) -> Expr<T>

Consume self and produce an Expr<T>. Read more
Source§

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

Produce an Expr<T> from a reference without consuming self. Read more
Source§

impl Not for Expr<bool>

Source§

type Output = Expr<bool>

The resulting type after applying the ! operator.
Source§

fn not(self) -> Expr<bool>

Performs the unary ! operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Expr<T>
where PhantomData<T>: Freeze,

§

impl<T> RefUnwindSafe for Expr<T>

§

impl<T> Send for Expr<T>
where PhantomData<T>: Send,

§

impl<T> Sync for Expr<T>
where PhantomData<T>: Sync,

§

impl<T> Unpin for Expr<T>
where PhantomData<T>: Unpin,

§

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more