macro_rules! impl_hash_for_single_field {
($ty:ty) => {
#[cfg(feature = "hash")]
#[cfg_attr(docsrs, doc(cfg(feature = "hash")))]
impl core::hash::Hash for $ty {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.0.hash(state);
}
}
};
}
macro_rules! impl_hash_with_fields {
($ty:ty; $($field:ident),+) => {
#[cfg(feature = "hash")]
#[cfg_attr(docsrs, doc(cfg(feature = "hash")))]
impl core::hash::Hash for $ty {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
$(self.$field.hash(state);)+
}
}
};
}
macro_rules! impl_hash_for_fieldless_enum {
($ty:ty) => {
#[cfg(feature = "hash")]
#[cfg_attr(docsrs, doc(cfg(feature = "hash")))]
impl core::hash::Hash for $ty {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
core::mem::discriminant(self).hash(state);
}
}
};
}
macro_rules! impl_ord_for_single_field {
($ty:ty) => {
#[cfg(feature = "ord")]
#[cfg_attr(docsrs, doc(cfg(feature = "ord")))]
impl core::cmp::PartialOrd for $ty {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
self.0.partial_cmp(&other.0)
}
}
#[cfg(feature = "ord")]
#[cfg_attr(docsrs, doc(cfg(feature = "ord")))]
impl core::cmp::Ord for $ty {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
self.0.cmp(&other.0)
}
}
};
}
macro_rules! impl_ord_with_fields {
($ty:ty; $($field:ident),+) => {
#[cfg(feature = "ord")]
#[cfg_attr(docsrs, doc(cfg(feature = "ord")))]
impl core::cmp::PartialOrd for $ty {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
Some(self.cmp(other))
}
}
#[cfg(feature = "ord")]
#[cfg_attr(docsrs, doc(cfg(feature = "ord")))]
impl core::cmp::Ord for $ty {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
($(&self.$field),+).cmp(&($(&other.$field),+))
}
}
};
}
macro_rules! impl_ord_for_fieldless_enum {
($ty:ty) => {
#[cfg(feature = "ord")]
#[cfg_attr(docsrs, doc(cfg(feature = "ord")))]
impl core::cmp::PartialOrd for $ty {
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
(*self as u8).partial_cmp(&(*other as u8))
}
}
#[cfg(feature = "ord")]
#[cfg_attr(docsrs, doc(cfg(feature = "ord")))]
impl core::cmp::Ord for $ty {
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
(*self as u8).cmp(&(*other as u8))
}
}
};
}