From e075224f9a327b53b5a92f8fc13f00721723a635 Mon Sep 17 00:00:00 2001 From: Jeremy Kaplan Date: Mon, 12 Dec 2022 23:16:54 -0800 Subject: [PATCH] Readability order --- 2022/src/bin/day13.rs | 52 +++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/2022/src/bin/day13.rs b/2022/src/bin/day13.rs index 3c55d70..d6822c7 100644 --- a/2022/src/bin/day13.rs +++ b/2022/src/bin/day13.rs @@ -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 { + 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 { - 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 {