From 66e300be0a8c34c23686418d6a3f6cb60bb792ea Mon Sep 17 00:00:00 2001 From: teor Date: Mon, 14 Dec 2020 11:25:50 +1000 Subject: [PATCH] Cleanup the ExpandedDifficulty PartialOrd impl (#1466) --- zebra-chain/src/work/difficulty.rs | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/zebra-chain/src/work/difficulty.rs b/zebra-chain/src/work/difficulty.rs index 03526a3ec..b8fcdf917 100644 --- a/zebra-chain/src/work/difficulty.rs +++ b/zebra-chain/src/work/difficulty.rs @@ -451,28 +451,26 @@ impl PartialOrd for ExpandedDifficulty { impl PartialEq for block::Hash { /// Is `self` equal to `other`? /// - /// See `partial_cmp` for details. + /// See `::partial_cmp` + /// for details. fn eq(&self, other: &ExpandedDifficulty) -> bool { other.eq(self) } } impl PartialOrd for block::Hash { - /// `block::Hash`es are compared with `ExpandedDifficulty` thresholds by - /// converting the hash to a 256-bit integer in little-endian order. + /// How does `self` compare to `other`? + /// + /// See `::partial_cmp` + /// for details. fn partial_cmp(&self, other: &ExpandedDifficulty) -> Option { - use Ordering::*; - - // Use the base implementation, but reverse the order. - match other - .partial_cmp(self) - .expect("difficulties and hashes have a total order") - { - Less => Greater, - Greater => Less, - Equal => Equal, - } - .into() + Some( + // Use the canonical implementation, but reverse the order + other + .partial_cmp(self) + .expect("difficulties and hashes have a total order") + .reverse(), + ) } }