1 #[cfg(feature = "postgres")] 2 use expression::SelectableExpression; 3 use 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 12 pub trait DistinctDsl { 13 /// The type returned by `.distinct` 14 type Output; 15 16 /// See the trait documentation. distinct(self) -> Self::Output17 fn distinct(self) -> Self::Output; 18 } 19 20 impl<T> DistinctDsl for T 21 where 22 T: Table, 23 T::Query: DistinctDsl, 24 { 25 type Output = <T::Query as DistinctDsl>::Output; 26 distinct(self) -> Self::Output27 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")] 40 pub trait DistinctOnDsl<Selection> { 41 /// The type returned by `.distinct_on` 42 type Output; 43 44 /// See the trait documentation distinct_on(self, selection: Selection) -> Self::Output45 fn distinct_on(self, selection: Selection) -> Self::Output; 46 } 47 48 #[cfg(feature = "postgres")] 49 impl<T, Selection> DistinctOnDsl<Selection> for T 50 where 51 Selection: SelectableExpression<T>, 52 T: Table, 53 T::Query: DistinctOnDsl<Selection>, 54 { 55 type Output = <T::Query as DistinctOnDsl<Selection>>::Output; 56 distinct_on(self, selection: Selection) -> Self::Output57 fn distinct_on(self, selection: Selection) -> Self::Output { 58 self.as_query().distinct_on(selection) 59 } 60 } 61