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

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 dyn BoxableExpression<QS, DB, SqlType = ST> + 'a[src]

type QueryId = ()

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


impl<QS, T, DB> BoxableExpression<QS, DB> for T where
    DB: Backend,
    T: Expression,
    T: SelectableExpression<QS>,
    T: NonAggregate,
    T: QueryFragment<DB>, 

Loading content...