1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
/// # ⚠ THIS IS AN INTERNAL IMPLEMENTATION DETAIL. DO NOT USE.
///
/// Given an implementation of `T == U`, implements:
/// - `&T == U`
/// - `T == &U`
///
/// We don't need to add `&T == &U` here because this is implemented automatically.
#[doc(hidden)]
#[macro_export]
macro_rules! __internal__forward_ref_partial_eq {
($t:ty, $u:ty) => {
// `&T == U`
impl<'a> PartialEq<$u> for &'a $t {
#[inline]
fn eq(&self, rhs: &$u) -> bool {
**self == *rhs // Implement via T == U
}
}
// `T == &U`
impl PartialEq<&$u> for $t {
#[inline]
fn eq(&self, rhs: &&$u) -> bool {
*self == **rhs // Implement via T == U
}
}
};
}
/// implements binary operators "&T op U", "T op &U", "&T op &U"
/// based on "T op U" where T and U are expected to be `Copy`able
///
/// Copied from `libcore`
macro_rules! forward_ref_binop {
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
impl<'a> $imp<$u> for &'a $t {
type Output = <$t as $imp<$u>>::Output;
#[inline]
#[track_caller]
fn $method(self, other: $u) -> <$t as $imp<$u>>::Output {
$imp::$method(*self, other)
}
}
impl $imp<&$u> for $t {
type Output = <$t as $imp<$u>>::Output;
#[inline]
#[track_caller]
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
$imp::$method(self, *other)
}
}
impl $imp<&$u> for &$t {
type Output = <$t as $imp<$u>>::Output;
#[inline]
#[track_caller]
fn $method(self, other: &$u) -> <$t as $imp<$u>>::Output {
$imp::$method(*self, *other)
}
}
};
}
/// implements "T op= &U", based on "T op= U"
/// where U is expected to be `Copy`able
///
/// Copied from `libcore`
macro_rules! forward_ref_op_assign {
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
impl $imp<&$u> for $t {
#[inline]
#[track_caller]
fn $method(&mut self, other: &$u) {
$imp::$method(self, *other);
}
}
};
}
pub(crate) use {forward_ref_binop, forward_ref_op_assign};