Watch
1
0
Fork
You've already forked advent-of-code
0

Readability order

This commit is contained in:
Jeremy Kaplan 2022-12-12 23:16:54 -08:00
commit e075224f9a

View file

@ -118,6 +118,32 @@ impl Data {
}
}
impl PartialEq for Data {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == Ordering::Equal
}
}
impl Eq for Data {}
impl PartialOrd for Data {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Data {
fn cmp(&self, other: &Self) -> Ordering {
match (self, other) {
(Data::Value(l), Data::Value(r)) => l.cmp(r),
(Data::List(l), Data::List(r)) => Data::zip_cmp(l, r),
(Data::Value(_), Data::List(_)) => self.to_list().cmp(other),
(Data::List(_), Data::Value(_)) => self.cmp(&other.to_list()),
}
}
}
impl Data {
fn to_list(&self) -> Self {
match self {
@ -146,32 +172,6 @@ impl Data {
}
}
impl PartialEq for Data {
fn eq(&self, other: &Self) -> bool {
self.cmp(other) == Ordering::Equal
}
}
impl Eq for Data {}
impl PartialOrd for Data {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Data {
fn cmp(&self, other: &Self) -> Ordering {
match (self, other) {
(Data::Value(l), Data::Value(r)) => l.cmp(r),
(Data::List(l), Data::List(r)) => Data::zip_cmp(l, r),
(Data::Value(_), Data::List(_)) => self.to_list().cmp(other),
(Data::List(_), Data::Value(_)) => self.cmp(&other.to_list()),
}
}
}
impl Display for Data {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {