Trait diesel::expression::BoxableExpression[][src]

pub trait BoxableExpression<QS, DB> where
    DB: Backend,
    Self: Expression,
    Self: SelectableExpression<QS>,
    Self: NonAggregate,
    Self: QueryFragment<DB>, 
{ }

Helper trait used when boxing expressions.

In Rust you cannot create a trait object with more than one trait. This type has all of the additional traits you would want when using Box<Expression> as a single trait object.

This is typically used as the return type of a function. For cases where you want to dynamically construct a query, boxing the query is usually more ergonomic.


use diesel::sql_types::Bool;

enum Search {

type DB = diesel::sqlite::Sqlite;

fn find_user(search: Search) -> Box<BoxableExpression<users::table, DB, SqlType = Bool>> {
    match search {
        Search::Id(id) => Box::new(users::id.eq(id)),
        Search::Name(name) => Box::new(users::name.eq(name)),

let user_one = users::table
assert_eq!((1, String::from("Sean")), user_one);

let tess = users::table
assert_eq!((2, String::from("Tess")), tess);

Trait Implementations

impl<'a, QS, ST, DB> QueryId for BoxableExpression<QS, DB, SqlType = ST> + 'a

A type which uniquely represents Self in a SQL query. Read more

HAS_STATIC_QUERY_ID: bool = false

Can the SQL generated by Self be uniquely identified by its type? Read more

Returns the type id of Self::QueryId if Self::HAS_STATIC_QUERY_ID. Returns None otherwise. Read more