use std::{cmp::Ordering, fmt};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Equality {
NotEqual,
Equal,
Unknown,
}
impl fmt::Display for Equality {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NotEqual => "!=".fmt(f),
Self::Equal => "==".fmt(f),
Self::Unknown => "?=".fmt(f),
}
}
}
impl PartialOrd for Equality {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
match (self, other) {
(Self::NotEqual, Self::NotEqual) => Some(Ordering::Equal),
(Self::NotEqual, Self::Equal) => Some(Ordering::Less),
(Self::NotEqual, Self::Unknown) => Some(Ordering::Less),
(Self::Equal, Self::NotEqual) => Some(Ordering::Greater),
(Self::Equal, Self::Equal) => Some(Ordering::Equal),
(Self::Equal, Self::Unknown) => Some(Ordering::Less),
(Self::Unknown, Self::NotEqual) => Some(Ordering::Greater),
(Self::Unknown, Self::Equal) => Some(Ordering::Greater),
(Self::Unknown, Self::Unknown) => None,
}
}
}
impl From<bool> for Equality {
fn from(eq: bool) -> Self {
if eq {
Equality::Equal
} else {
Equality::NotEqual
}
}
}
impl From<Equality> for bool {
fn from(equality: Equality) -> bool {
match equality {
Equality::NotEqual => false,
Equality::Equal => true,
Equality::Unknown => false,
}
}
}