#[macro_export]
macro_rules! impl_ops_cmp {
(impl $imp:ident, $imo:ident, $method:ident for $t:ty, $u:ty, $sgn:expr) => {
impl<'a> $imp<$u> for &'a mut $t {
#[inline]
fn eq(&self, rhs: &$u) -> bool {
self.$method(rhs) == 0
}
}
impl<'a> $imo<$u> for &'a mut $t {
#[inline]
fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
(self.$method(rhs) * $sgn).partial_cmp(&0)
}
}
impl $imp<$u> for $t {
#[inline]
fn eq(&self, rhs: &$u) -> bool {
self.$method(rhs) == 0
}
}
impl $imo<$u> for $t {
#[inline]
fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
(self.$method(rhs) * $sgn).partial_cmp(&0)
}
}
};
}
pub use impl_ops_cmp;
#[macro_export]
macro_rules! impl_ops_cmp_p {
(impl $imp:ident, $imo:ident, $method:ident for $t:ty, $u:ty, $sgn:expr) => {
impl<'a> $imp<$u> for &'a mut $t {
#[inline]
fn eq(&self, rhs: &$u) -> bool {
<$t>::eq(self, rhs)
}
}
impl<'a> $imo<$u> for &'a mut $t {
#[inline]
fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
<$t>::partial_cmp(self, rhs)
}
}
impl<'a> $imp<$u> for &'a $t {
#[inline]
fn eq(&self, rhs: &$u) -> bool {
<$t>::eq(self, rhs)
}
}
impl<'a> $imo<$u> for &'a $t {
#[inline]
fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
<$t>::partial_cmp(self, rhs)
}
}
impl $imp<$u> for $t {
#[inline]
fn eq(&self, rhs: &$u) -> bool {
self.$method(*rhs) == 0
}
}
impl $imo<$u> for $t {
#[inline]
fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
(self.$method(*rhs) * $sgn).partial_cmp(&0)
}
}
impl_ops_cmp_q!{impl $imp, $imo, for $u, $t}
};
}
pub use impl_ops_cmp_p;
#[macro_export]
macro_rules! impl_ops_cmp_q {
(impl $imp:ident, $imo:ident, for $t:ty, $u:ty) => {
impl<'a> $imp<&'a mut $u> for $t {
#[inline]
fn eq(&self, rhs: &&'a mut $u) -> bool {
(*rhs).eq(self)
}
}
impl<'a> $imo<&'a mut $u> for $t {
#[inline]
fn partial_cmp(&self, rhs: &&'a mut $u) -> Option<Ordering> {
(*rhs).partial_cmp(self).map(Ordering::reverse)
}
}
impl<'a> $imp<&'a $u> for $t {
#[inline]
fn eq(&self, rhs: &&'a $u) -> bool {
(*rhs).eq(self)
}
}
impl<'a> $imo<&'a $u> for $t {
#[inline]
fn partial_cmp(&self, rhs: &&'a $u) -> Option<Ordering> {
(*rhs).partial_cmp(self).map(Ordering::reverse)
}
}
impl $imp<$u> for $t {
#[inline]
fn eq(&self, rhs: &$u) -> bool {
rhs.eq(self)
}
}
impl $imo<$u> for $t {
#[inline]
fn partial_cmp(&self, rhs: &$u) -> Option<Ordering> {
rhs.partial_cmp(self).map(Ordering::reverse)
}
}
};
}
pub use impl_ops_cmp_q;