Skip to main content

IntoExpr

Trait IntoExpr 

Source
pub trait IntoExpr {
    // Required method
    fn into_expr(self) -> Expr;
}
Expand description

Anything that can stand where an expression is expected.

This is bob’s progressive enhancement, made a trait: a &'static str is raw SQL, a number is a SQL literal, a Value is a bound argument, and an Expr is itself. Every builder slot in keelson takes impl IntoExpr, so the same call site accepts a hand-written fragment today and a structured expression tomorrow with no change in shape.

§Which conversion each type gets, and why

fromtorationale
Expritself
&'static str, String, Cow<'static, str>Expr::Rawbob writes a Go string verbatim
i8..i64, u8..u64, f32, f64, boolExpr::Rawbob’s fallback formats any other value into the SQL, which is what makes LIMIT 20 a literal
ValueExpr::Arga Value is data, and data is bound, never interpolated
DynExprExpr::Customthe escape hatch for a dialect’s own shape

The split on the last two rows is the whole safety story: text that the program wrote is SQL, and text that came from outside is a Value. There is deliberately no impl turning &str into a bound string — that would make the same call site mean two different things depending on the author’s intent, and bob does not do it either.

§Why &'static str and not &str

An Expr stores Cow<'static, str>, so that no public type needs a lifetime parameter. A &'static str — which is what a literal is — borrows for free; a shorter-lived &str would have to be copied on every conversion, silently allocating for the overwhelmingly common literal case. Pass a String when the text is computed.

Required Methods§

Source

fn into_expr(self) -> Expr

Perform the conversion.

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 for &'static str

Source§

impl IntoExpr for Arc<dyn Expression>

Source§

impl IntoExpr for Cow<'static, str>

Source§

impl IntoExpr for String

Source§

impl IntoExpr for bool

Source§

impl IntoExpr for f32

Source§

impl IntoExpr for f64

Source§

impl IntoExpr for i8

Source§

impl IntoExpr for i16

Source§

impl IntoExpr for i32

Source§

impl IntoExpr for i64

Source§

impl IntoExpr for isize

Source§

impl IntoExpr for u8

Source§

impl IntoExpr for u16

Source§

impl IntoExpr for u32

Source§

impl IntoExpr for u64

Source§

impl IntoExpr for usize

Implementors§