Skip to content

Commit

Permalink
Simplify manual PartialOrd for AdressView
Browse files Browse the repository at this point in the history
This matches the derived implementation, but doesn't change under
refactoring.
  • Loading branch information
cronokirby committed Dec 13, 2024
1 parent f34601f commit 74aa056
Showing 1 changed file with 8 additions and 29 deletions.
37 changes: 8 additions & 29 deletions crates/core/keys/src/address/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,46 +103,25 @@ impl TryFrom<pb::AddressView> for AddressView {

// Canonical ordering for serialization
impl PartialOrd for AddressView {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
use AddressView::*;
// Opaque < Decoded
match (self, other) {
(AddressView::Opaque { address: a1 }, AddressView::Opaque { address: a2 }) => {
a1.partial_cmp(a2)
}
(Opaque { .. }, Decoded { .. }) => Some(Ordering::Less),
(Decoded { .. }, Opaque { .. }) => Some(Ordering::Greater),
(Opaque { address: a1 }, Opaque { address: a2 }) => a1.partial_cmp(a2),
(
AddressView::Decoded {
Decoded {
address: a1,
index: i1,
wallet_id: w1,
},
AddressView::Decoded {
Decoded {
address: a2,
index: i2,
wallet_id: w2,
},
) => match a1.partial_cmp(a2) {
Some(Ordering::Equal) => match i1.partial_cmp(i2) {
Some(Ordering::Equal) => w1.partial_cmp(w2),
ord => ord,
},
ord => ord,
},
(
AddressView::Opaque { address: _ },
AddressView::Decoded {
address: _,
index: _,
wallet_id: _,
},
) => Some(Ordering::Less),
(
AddressView::Decoded {
address: _,
index: _,
wallet_id: _,
},
AddressView::Opaque { address: _ },
) => Some(Ordering::Greater),
) => (a1, i1, w1).partial_cmp(&(a2, i2, w2)),
}
}
}
Expand Down

0 comments on commit 74aa056

Please sign in to comment.