diesel/query_dsl/
distinct_dsl.rs

1#[cfg(feature = "postgres")]
2use expression::SelectableExpression;
3use query_source::Table;
4
5/// The `distinct` method
6///
7/// This trait should not be relied on directly by most apps. Its behavior is
8/// provided by [`QueryDsl`]. However, you may need a where clause on this trait
9/// to call `distinct` from generic code.
10///
11/// [`QueryDsl`]: ../trait.QueryDsl.html
12pub trait DistinctDsl {
13    /// The type returned by `.distinct`
14    type Output;
15
16    /// See the trait documentation.
17    fn distinct(self) -> Self::Output;
18}
19
20impl<T> DistinctDsl for T
21where
22    T: Table,
23    T::Query: DistinctDsl,
24{
25    type Output = <T::Query as DistinctDsl>::Output;
26
27    fn distinct(self) -> Self::Output {
28        self.as_query().distinct()
29    }
30}
31
32/// The `distinct_on` method
33///
34/// This trait should not be relied on directly by most apps. Its behavior is
35/// provided by [`QueryDsl`]. However, you may need a where clause on this trait
36/// to call `distinct_on` from generic code.
37///
38/// [`QueryDsl`]: ../trait.QueryDsl.html
39#[cfg(feature = "postgres")]
40pub trait DistinctOnDsl<Selection> {
41    /// The type returned by `.distinct_on`
42    type Output;
43
44    /// See the trait documentation
45    fn distinct_on(self, selection: Selection) -> Self::Output;
46}
47
48#[cfg(feature = "postgres")]
49impl<T, Selection> DistinctOnDsl<Selection> for T
50where
51    Selection: SelectableExpression<T>,
52    T: Table,
53    T::Query: DistinctOnDsl<Selection>,
54{
55    type Output = <T::Query as DistinctOnDsl<Selection>>::Output;
56
57    fn distinct_on(self, selection: Selection) -> Self::Output {
58        self.as_query().distinct_on(selection)
59    }
60}