| 1 |
use crate::expression::grouped::Grouped; |
| 2 |
use crate::expression::operators::And; |
| 3 |
use crate::expression::Expression; |
| 4 |
use crate::expression_methods::*; |
| 5 |
use crate::sql_types::Bool; |
| 6 |
|
| 7 |
/// This method is used by `FindDsl` to work with tuples. Because we cannot |
| 8 |
/// express this without specialization or overlapping impls, it is brute force |
| 9 |
/// implemented on columns in the `column!` macro. |
| 10 |
#[doc(hidden)] |
| 11 |
pub trait EqAll<Rhs> { |
| 12 |
type Output: Expression<SqlType = Bool>; |
| 13 |
|
| 14 |
fn eq_all(self, rhs: Rhs) -> Self::Output; |
| 15 |
} |
| 16 |
|
| 17 |
macro_rules! impl_eq_all { |
| 18 |
// General case for 2+ elements |
| 19 |
( |
| 20 |
($Left1:ident, $($Left:ident,)+) |
| 21 |
($Right1:ident, $($Right:ident,)+) |
| 22 |
) => { |
| 23 |
#[allow(non_snake_case)] |
| 24 |
impl<$Left1, $($Left,)+ $Right1, $($Right,)+> |
| 25 |
EqAll<($Right1, $($Right,)+)> for ($Left1, $($Left,)+) |
| 26 |
where |
| 27 |
$Left1: EqAll<$Right1>, |
| 28 |
($($Left,)+): EqAll<($($Right,)+)>, |
| 29 |
{ |
| 30 |
type Output = Grouped<And< |
| 31 |
<$Left1 as EqAll<$Right1>>::Output, |
| 32 |
<($($Left,)+) as EqAll<($($Right,)+)>>::Output, |
| 33 |
>>; |
| 34 |
|
| 35 |
fn eq_all(self, rhs: ($Right1, $($Right,)+)) -> Self::Output { |
| 36 |
let ($Left1, $($Left,)+) = self; |
| 37 |
let ($Right1, $($Right,)+) = rhs; |
| 38 |
$Left1.eq_all($Right1).and(($($Left,)+).eq_all(($($Right,)+))) |
| 39 |
} |
| 40 |
} |
| 41 |
}; |
| 42 |
|
| 43 |
// Special case for 1 element |
| 44 |
( |
| 45 |
($Left:ident,) ($Right:ident,) |
| 46 |
) => { |
| 47 |
impl<$Left, $Right> EqAll<($Right,)> for ($Left,) |
| 48 |
where |
| 49 |
$Left: EqAll<$Right>, |
| 50 |
{ |
| 51 |
type Output = <$Left as EqAll<$Right>>::Output; |
| 52 |
|
| 53 |
fn eq_all(self, rhs: ($Right,)) -> Self::Output { |
| 54 |
self.0.eq_all(rhs.0) |
| 55 |
} |
| 56 |
} |
| 57 |
}; |
| 58 |
} |
| 59 |
|
| 60 |
macro_rules! impl_eq_all_for_all_tuples { |
| 61 |
($( |
| 62 |
$unused1:tt { |
| 63 |
$($unused2:tt -> $Left:ident, $Right:ident, $unused3:tt,)+ |
| 64 |
} |
| 65 |
)+) => { |
| 66 |
$( |
| 67 |
impl_eq_all!(($($Left,)+) ($($Right,)+)); |
| 68 |
)+ |
| 69 |
}; |
| 70 |
} |
| 71 |
|
| 72 |
diesel_derives::__diesel_for_each_tuple!(impl_eq_all_for_all_tuples); |