helper: macro to generate Eq,PartialEq,PartialOrd impls for an Ord type.

This commit is contained in:
2026-04-12 06:36:46 +01:00
committed by oreodave
parent ddfb137fb1
commit 76f180d4c6

View File

@@ -28,3 +28,26 @@ where
I: ExactSizeIterator<Item = T>,
{
}
/** A macro which generates Eq, PartialEq, and PartialOrd implementations for
some given type. These implementations are dependent on Ord already being
implemented for that type. */
macro_rules! impl_cmp_eq_on_ord {
($type:ident) => {
impl PartialEq for $type {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == std::cmp::Ordering::Equal
}
}
impl Eq for $type {}
impl PartialOrd for $type {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
};
}
pub(crate) use impl_cmp_eq_on_ord;