diesel/expression/
bound.rs

1use std::marker::PhantomData;
2
3use super::*;
4use crate::query_builder::*;
5use crate::result::QueryResult;
6use crate::serialize::ToSql;
7use crate::sql_types::DieselNumericOps;
8
9#[doc(hidden)] // This is used by the `AsExpression` derive
10#[derive(Debug, Clone, Copy, DieselNumericOps)]
11pub struct Bound<T, U> {
12    pub(crate) item: U,
13    _marker: PhantomData<T>,
14}
15
16impl<T, U> Bound<T, U> {
17    #[doc(hidden)] // This is used by the `AsExpression` derive
18    pub fn new(item: U) -> Self {
19        Bound {
20            item,
21            _marker: PhantomData,
22        }
23    }
24}
25
26impl<T, U> Expression for Bound<T, U>
27where
28    T: SqlType + TypedExpressionType,
29{
30    type SqlType = T;
31}
32
33impl<T, U, DB> QueryFragment<DB> for Bound<T, U>
34where
35    DB: Backend + HasSqlType<T>,
36    U: ToSql<T, DB>,
37{
38    fn walk_ast<'b>(&'b self, mut pass: AstPass<'_, 'b, DB>) -> QueryResult<()> {
39        pass.push_bind_param(&self.item)?;
40        Ok(())
41    }
42}
43
44impl<T: QueryId, U> QueryId for Bound<T, U> {
45    type QueryId = Bound<T::QueryId, ()>;
46
47    const HAS_STATIC_QUERY_ID: bool = T::HAS_STATIC_QUERY_ID;
48}
49
50impl<T, U, QS> SelectableExpression<QS> for Bound<T, U> where Bound<T, U>: AppearsOnTable<QS> {}
51
52impl<T, U, QS> AppearsOnTable<QS> for Bound<T, U> where Bound<T, U>: Expression {}
53
54impl<T, U, GB> ValidGrouping<GB> for Bound<T, U> {
55    type IsAggregate = is_aggregate::Never;
56}