|
| 1 | +use expression::Expression; |
| 2 | +use expression::predicates::And; |
| 3 | +use expression::expression_methods::*; |
| 4 | +use types::Bool; |
| 5 | + |
| 6 | +/// This method is used by `FindDsl` to work with tuples. Because we cannot |
| 7 | +/// express this without specialization or overlapping impls, it is brute force |
| 8 | +/// implemented on columns in the `column!` macro. |
| 9 | +#[doc(hidden)] |
| 10 | +pub trait EqAll<Rhs> { |
| 11 | + type Output: Expression<SqlType=Bool>; |
| 12 | + |
| 13 | + fn eq_all(self, rhs: Rhs) -> Self::Output; |
| 14 | +} |
| 15 | + |
| 16 | +// FIXME: This is much easier to represent with a macro once macro types are stable |
| 17 | +// which appears to be slated for 1.13 |
| 18 | +impl<L1, L2, R1, R2> EqAll<(R1, R2)> for (L1, L2) where |
| 19 | + L1: EqAll<R1>, |
| 20 | + L2: EqAll<R2>, |
| 21 | +{ |
| 22 | + type Output = And<<L1 as EqAll<R1>>::Output, <L2 as EqAll<R2>>::Output>; |
| 23 | + |
| 24 | + fn eq_all(self, rhs: (R1, R2)) -> Self::Output { |
| 25 | + self.0.eq_all(rhs.0).and(self.1.eq_all(rhs.1)) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +impl<L1, L2, L3, R1, R2, R3> EqAll<(R1, R2, R3)> for (L1, L2, L3) where |
| 30 | + L1: EqAll<R1>, |
| 31 | + L2: EqAll<R2>, |
| 32 | + L3: EqAll<R3>, |
| 33 | +{ |
| 34 | + type Output = And<<L1 as EqAll<R1>>::Output, And<<L2 as EqAll<R2>>::Output, <L3 as EqAll<R3>>::Output>>; |
| 35 | + |
| 36 | + fn eq_all(self, rhs: (R1, R2, R3)) -> Self::Output { |
| 37 | + self.0.eq_all(rhs.0).and( |
| 38 | + self.1.eq_all(rhs.1).and(self.2.eq_all(rhs.2))) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +impl<L1, L2, L3, L4, R1, R2, R3, R4> EqAll<(R1, R2, R3, R4)> for (L1, L2, L3, L4) where |
| 43 | + L1: EqAll<R1>, |
| 44 | + L2: EqAll<R2>, |
| 45 | + L3: EqAll<R3>, |
| 46 | + L4: EqAll<R4>, |
| 47 | +{ |
| 48 | + type Output = And<<L1 as EqAll<R1>>::Output, And<<L2 as EqAll<R2>>::Output, And<<L3 as EqAll<R3>>::Output, <L4 as EqAll<R4>>::Output>>>; |
| 49 | + |
| 50 | + fn eq_all(self, rhs: (R1, R2, R3, R4)) -> Self::Output { |
| 51 | + self.0.eq_all(rhs.0).and( |
| 52 | + self.1.eq_all(rhs.1).and( |
| 53 | + self.2.eq_all(rhs.2).and( |
| 54 | + self.3.eq_all(rhs.3) |
| 55 | + ))) |
| 56 | + } |
| 57 | +} |
0 commit comments