1use crate::dsl::{Filter, OrFilter};
2use crate::expression_methods::*;
3use crate::query_source::*;
45/// The `filter` 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 `filter` from generic code.
10///
11/// [`QueryDsl`]: crate::QueryDsl
12pub trait FilterDsl<Predicate> {
13/// The type returned by `.filter`.
14type Output;
1516/// See the trait documentation.
17fn filter(self, predicate: Predicate) -> Self::Output;
18}
1920impl<T, Predicate> FilterDsl<Predicate> for T
21where
22T: Table,
23 T::Query: FilterDsl<Predicate>,
24{
25type Output = Filter<T::Query, Predicate>;
2627fn filter(self, predicate: Predicate) -> Self::Output {
28self.as_query().filter(predicate)
29 }
30}
3132/// The `find` 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 `find` from generic code.
37///
38/// [`QueryDsl`]: crate::QueryDsl
39pub trait FindDsl<PK> {
40/// The type returned by `.find`.
41type Output;
4243/// See the trait documentation.
44fn find(self, id: PK) -> Self::Output;
45}
4647impl<T, PK> FindDsl<PK> for T
48where
49T: Table + FilterDsl<<<T as Table>::PrimaryKey as EqAll<PK>>::Output>,
50 T::PrimaryKey: EqAll<PK>,
51{
52type Output = Filter<Self, <T::PrimaryKey as EqAll<PK>>::Output>;
5354fn find(self, id: PK) -> Self::Output {
55let primary_key = self.primary_key();
56self.filter(primary_key.eq_all(id))
57 }
58}
5960/// The `or_filter` method
61///
62/// This trait should not be relied on directly by most apps. Its behavior is
63/// provided by [`QueryDsl`]. However, you may need a where clause on this trait
64/// to call `or_filter` from generic code.
65///
66/// [`QueryDsl`]: crate::QueryDsl
67pub trait OrFilterDsl<Predicate> {
68/// The type returned by `.filter`.
69type Output;
7071/// See the trait documentation.
72fn or_filter(self, predicate: Predicate) -> Self::Output;
73}
7475impl<T, Predicate> OrFilterDsl<Predicate> for T
76where
77T: Table,
78 T::Query: OrFilterDsl<Predicate>,
79{
80type Output = OrFilter<T::Query, Predicate>;
8182fn or_filter(self, predicate: Predicate) -> Self::Output {
83self.as_query().or_filter(predicate)
84 }
85}