1use std::{cmp::Ordering, fmt};
2
3#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
5pub enum Equality {
6 NotEqual,
8 Equal,
10 Unknown,
17}
18
19impl fmt::Display for Equality {
20 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21 match self {
22 Self::NotEqual => "!=".fmt(f),
23 Self::Equal => "==".fmt(f),
24 Self::Unknown => "?=".fmt(f),
25 }
26 }
27}
28
29impl PartialOrd for Equality {
30 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
31 match (self, other) {
37 (Self::NotEqual, Self::NotEqual) => Some(Ordering::Equal),
38 (Self::NotEqual, Self::Equal) => Some(Ordering::Less),
39 (Self::NotEqual, Self::Unknown) => Some(Ordering::Less),
40 (Self::Equal, Self::NotEqual) => Some(Ordering::Greater),
41 (Self::Equal, Self::Equal) => Some(Ordering::Equal),
42 (Self::Equal, Self::Unknown) => Some(Ordering::Less),
43 (Self::Unknown, Self::NotEqual) => Some(Ordering::Greater),
44 (Self::Unknown, Self::Equal) => Some(Ordering::Greater),
45 (Self::Unknown, Self::Unknown) => None,
46 }
47 }
48}
49
50impl From<bool> for Equality {
51 fn from(eq: bool) -> Self {
52 if eq {
53 Equality::Equal
54 } else {
55 Equality::NotEqual
56 }
57 }
58}
59
60impl From<Equality> for bool {
61 fn from(equality: Equality) -> bool {
62 match equality {
63 Equality::NotEqual => false,
64 Equality::Equal => true,
65 Equality::Unknown => false,
66 }
67 }
68}