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§
Sourcefn by_ref(&self) -> Expr<T>
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<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)
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)
fn into_expr(self) -> Expr<(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)>
fn by_ref(&self) -> Expr<(T0, T1, T2, T3, T4, T5, T6, T7, T8, 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)
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)
fn into_expr(self) -> Expr<(T0, T1, T2, T3, T4, T5, T6, T7, T8)>
fn by_ref(&self) -> Expr<(T0, T1, T2, T3, T4, T5, T6, T7, 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)
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)
fn into_expr(self) -> Expr<(T0, T1, T2, T3, T4, T5, T6, T7)>
fn by_ref(&self) -> Expr<(T0, T1, T2, T3, T4, T5, T6, 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)
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)
fn into_expr(self) -> Expr<(T0, T1, T2, T3, T4, T5, T6)>
fn by_ref(&self) -> Expr<(T0, T1, T2, T3, T4, T5, 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)
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)
fn into_expr(self) -> Expr<(T0, T1, T2, T3, T4, T5)>
fn by_ref(&self) -> Expr<(T0, T1, T2, T3, T4, 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)
impl<T0, E0, T1, E1, T2, E2, T3, E3, T4, E4> IntoExpr<(T0, T1, T2, T3, T4)> for (E0, E1, E2, E3, E4)
fn into_expr(self) -> Expr<(T0, T1, T2, T3, T4)>
fn by_ref(&self) -> Expr<(T0, T1, T2, T3, T4)>
Source§impl<T0, E0, T1, E1, T2, E2, T3, E3> IntoExpr<(T0, T1, T2, T3)> for (E0, E1, E2, E3)
impl<T0, E0, T1, E1, T2, E2, T3, E3> IntoExpr<(T0, T1, T2, T3)> for (E0, E1, E2, E3)
fn into_expr(self) -> Expr<(T0, T1, T2, T3)>
fn by_ref(&self) -> Expr<(T0, T1, T2, T3)>
Source§impl<T0, E0, T1, E1, T2, E2> IntoExpr<(T0, T1, T2)> for (E0, E1, E2)
impl<T0, E0, T1, E1, T2, E2> IntoExpr<(T0, T1, T2)> for (E0, E1, E2)
fn into_expr(self) -> Expr<(T0, T1, T2)>
fn by_ref(&self) -> Expr<(T0, T1, T2)>
Implementors§
impl<M> IntoExpr<List<M>> for CreateMany<M>where
M: Model,
impl<T, U> IntoExpr<U> for Path<T, U>
impl<T> IntoExpr<Arc<T>> for Twhere
T: IntoExpr<T>,
impl<T> IntoExpr<Box<T>> for Twhere
T: IntoExpr<T>,
impl<T> IntoExpr<Json<T>> for Json<T>where
T: Serialize,
impl<T> IntoExpr<Json<T>> for Twhere
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).
impl<T> IntoExpr<Option<T>> for Twhere
T: IntoExpr<T>,
impl<T> IntoExpr<Rc<T>> for Twhere
T: IntoExpr<T>,
impl<T> IntoExpr<T> for &Deferred<T>where
T: IntoExpr<T>,
impl<T> IntoExpr<T> for Batch<T>
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().