Skip to main content

IntoExpr

Trait IntoExpr 

Source
pub trait IntoExpr<T> {
    // Required methods
    fn into_expr(self) -> Expr<T>;
    fn by_ref(&self) -> Expr<T>;
}
Expand description

Convert a value into an Expr<T>.

This trait is the primary way Toasty coerces Rust values into query expressions. It is implemented for all scalar types (i64, String, bool, uuid::Uuid, …), Option<T>, tuples, slices, Vec, and arrays.

Generated code uses IntoExpr bounds on filter and setter methods so that callers can pass either a raw value or an already-constructed Expr:

// Both &str and Expr<String> implement IntoExpr<String>:
let _e1: Expr<String> = "Alice".into_expr();
let _e2: Expr<String> = Expr::<String>::from_untyped(
    toasty_core::stmt::Value::from("Bob"),
).into_expr();

§Implementing for custom types

If you have a newtype that wraps a supported scalar, implement IntoExpr by converting to the inner type first, then calling Expr::from_value.

Required Methods§

Source

fn into_expr(self) -> Expr<T>

Consume self and produce an Expr<T>.

§Examples
use toasty::stmt::{Expr, IntoExpr};

let _expr: Expr<i64> = 42_i64.into_expr();
let _expr: Expr<String> = "hello".into_expr();
Source

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

Produce an Expr<T> from a reference without consuming self.

For Copy types this clones the value. For non-Copy types like String this clones the underlying data.

§Examples
use toasty::stmt::{Expr, IntoExpr};

let value = 42_i64;
let _expr: Expr<i64> = value.by_ref();
// `value` is still usable
assert_eq!(value, 42);

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl IntoExpr<Option<String>> for &str

Source§

impl IntoExpr<String> for &str

Source§

impl IntoExpr<String> for String

Source§

impl IntoExpr<Uuid> for Uuid

Source§

impl IntoExpr<Vec<u8>> for Vec<u8>

Source§

fn into_expr(self) -> Expr<Vec<u8>>

Source§

fn by_ref(&self) -> Expr<Vec<u8>>

Source§

impl IntoExpr<bool> for bool

Source§

impl IntoExpr<f32> for f32

Source§

fn into_expr(self) -> Expr<f32>

Source§

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

Source§

impl IntoExpr<f64> for f64

Source§

fn into_expr(self) -> Expr<f64>

Source§

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

Source§

impl IntoExpr<i8> for i8

Source§

fn into_expr(self) -> Expr<i8>

Source§

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

Source§

impl IntoExpr<i16> for i16

Source§

fn into_expr(self) -> Expr<i16>

Source§

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

Source§

impl IntoExpr<i32> for i32

Source§

fn into_expr(self) -> Expr<i32>

Source§

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

Source§

impl IntoExpr<i64> for i64

Source§

fn into_expr(self) -> Expr<i64>

Source§

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

Source§

impl IntoExpr<isize> for isize

Source§

impl IntoExpr<u8> for u8

Source§

fn into_expr(self) -> Expr<u8>

Source§

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

Source§

impl IntoExpr<u16> for u16

Source§

fn into_expr(self) -> Expr<u16>

Source§

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

Source§

impl IntoExpr<u32> for u32

Source§

fn into_expr(self) -> Expr<u32>

Source§

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

Source§

impl IntoExpr<u64> for u64

Source§

fn into_expr(self) -> Expr<u64>

Source§

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

Source§

impl IntoExpr<usize> for usize

Source§

impl<T0, E0, T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8, T9, E9> IntoExpr<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)> for (E0, E1, E2, E3, E4, E5, E6, E7, E8, E9)
where E0: IntoExpr<T0>, E1: IntoExpr<T1>, E2: IntoExpr<T2>, E3: IntoExpr<T3>, E4: IntoExpr<T4>, E5: IntoExpr<T5>, E6: IntoExpr<T6>, E7: IntoExpr<T7>, E8: IntoExpr<T8>, E9: IntoExpr<T9>,

Source§

impl<T0, E0, T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7, T8, E8> IntoExpr<(T0, T1, T2, T3, T4, T5, T6, T7, T8)> for (E0, E1, E2, E3, E4, E5, E6, E7, E8)
where E0: IntoExpr<T0>, E1: IntoExpr<T1>, E2: IntoExpr<T2>, E3: IntoExpr<T3>, E4: IntoExpr<T4>, E5: IntoExpr<T5>, E6: IntoExpr<T6>, E7: IntoExpr<T7>, E8: IntoExpr<T8>,

Source§

impl<T0, E0, T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6, T7, E7> IntoExpr<(T0, T1, T2, T3, T4, T5, T6, T7)> for (E0, E1, E2, E3, E4, E5, E6, E7)
where E0: IntoExpr<T0>, E1: IntoExpr<T1>, E2: IntoExpr<T2>, E3: IntoExpr<T3>, E4: IntoExpr<T4>, E5: IntoExpr<T5>, E6: IntoExpr<T6>, E7: IntoExpr<T7>,

Source§

impl<T0, E0, T1, E1, T2, E2, T3, E3, T4, E4, T5, E5, T6, E6> IntoExpr<(T0, T1, T2, T3, T4, T5, T6)> for (E0, E1, E2, E3, E4, E5, E6)
where E0: IntoExpr<T0>, E1: IntoExpr<T1>, E2: IntoExpr<T2>, E3: IntoExpr<T3>, E4: IntoExpr<T4>, E5: IntoExpr<T5>, E6: IntoExpr<T6>,

Source§

impl<T0, E0, T1, E1, T2, E2, T3, E3, T4, E4, T5, E5> IntoExpr<(T0, T1, T2, T3, T4, T5)> for (E0, E1, E2, E3, E4, E5)
where E0: IntoExpr<T0>, E1: IntoExpr<T1>, E2: IntoExpr<T2>, E3: IntoExpr<T3>, E4: IntoExpr<T4>, E5: IntoExpr<T5>,

Source§

impl<T0, E0, T1, E1, T2, E2, T3, E3, T4, E4> IntoExpr<(T0, T1, T2, T3, T4)> for (E0, E1, E2, E3, E4)
where E0: IntoExpr<T0>, E1: IntoExpr<T1>, E2: IntoExpr<T2>, E3: IntoExpr<T3>, E4: IntoExpr<T4>,

Source§

impl<T0, E0, T1, E1, T2, E2, T3, E3> IntoExpr<(T0, T1, T2, T3)> for (E0, E1, E2, E3)
where E0: IntoExpr<T0>, E1: IntoExpr<T1>, E2: IntoExpr<T2>, E3: IntoExpr<T3>,

Source§

impl<T0, E0, T1, E1, T2, E2> IntoExpr<(T0, T1, T2)> for (E0, E1, E2)
where E0: IntoExpr<T0>, E1: IntoExpr<T1>, E2: IntoExpr<T2>,

Source§

impl<T0, E0, T1, E1> IntoExpr<(T0, T1)> for (E0, E1)
where E0: IntoExpr<T0>, E1: IntoExpr<T1>,

Source§

impl<T0, E0> IntoExpr<(T0,)> for (E0,)
where E0: IntoExpr<T0>,

Source§

impl<T, E> IntoExpr<List<T>> for &[E]
where E: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<List<T>>

Source§

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

Source§

impl<T, U, const N: usize> IntoExpr<List<T>> for &[U; N]
where U: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<List<T>>

Source§

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

Source§

impl<T, U, const N: usize> IntoExpr<List<T>> for [U; N]
where U: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<List<T>>

Source§

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

Source§

impl<T, U> IntoExpr<List<T>> for Vec<U>
where U: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<List<T>>

Source§

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

Source§

impl<T> IntoExpr<Option<T>> for &T
where T: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<Option<T>>

Source§

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

Source§

impl<T> IntoExpr<Option<T>> for Option<T>
where T: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<Option<T>>

Source§

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

Source§

impl<T> IntoExpr<T> for &Arc<T>
where T: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<T>

Source§

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

Source§

impl<T> IntoExpr<T> for &Box<T>
where T: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<T>

Source§

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

Source§

impl<T> IntoExpr<T> for &Rc<T>
where T: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<T>

Source§

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

Source§

impl<T> IntoExpr<T> for &T
where T: IntoExpr<T>,

Source§

fn into_expr(self) -> Expr<T>

Source§

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

Implementors§

Source§

impl<M> IntoExpr<List<M>> for CreateMany<M>
where M: Model,

Source§

impl<T, U> IntoExpr<U> for Path<T, U>

Source§

impl<T> IntoExpr<Arc<T>> for T
where T: IntoExpr<T>,

Source§

impl<T> IntoExpr<Box<T>> for T
where T: IntoExpr<T>,

Source§

impl<T> IntoExpr<Json<T>> for Json<T>
where T: Serialize,

Source§

impl<T> IntoExpr<Json<T>> for T
where T: Serialize,

Accept a bare T wherever the API expects IntoExpr<Json<T>>, so callers don’t have to spell Json(value) at setter sites:

ⓘ
// both forms work for a `payload: Json<Payload>` field
Repository::create().payload(Json(payload.clone())).exec(&mut db).await?;
Repository::create().payload(payload.clone()).exec(&mut db).await?;

The blanket only fires when T: serde::Serialize; it doesn’t overlap the explicit IntoExpr<Json<T>> for Json<T> impl because Json<U> itself is not Serialize (no derive on the wrapper).

Source§

impl<T> IntoExpr<Option<T>> for T
where T: IntoExpr<T>,

Source§

impl<T> IntoExpr<Rc<T>> for T
where T: IntoExpr<T>,

Source§

impl<T> IntoExpr<T> for &Deferred<T>
where T: IntoExpr<T>,

Source§

impl<T> IntoExpr<T> for Batch<T>

Source§

impl<T> IntoExpr<T> for Deferred<T>
where T: IntoExpr<T>,

Forwards the inner value’s expression encoding so a Deferred<T> field can be spliced into any site that accepts a T.

Deferred<T> is a load-state wrapper, not a value type, so the produced expression is Expr<T> (the value), never Expr<Deferred<T>>. Panics with the standard “deferred field not loaded” error if the value is in the unloaded state — matching .get() / .into_inner().

Source§

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