Skip to content

Commit

Permalink
fix ord impl too
Browse files Browse the repository at this point in the history
  • Loading branch information
adamspofford-dfinity committed Feb 21, 2025
1 parent a1def02 commit 2afc570
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion rust/candid/src/types/internal.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::CandidType;
use crate::idl_hash;
use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::fmt;

Expand Down Expand Up @@ -382,7 +383,7 @@ pub fn text_size(t: &Type, limit: i32) -> Result<i32, ()> {
}
}

#[derive(Debug, Eq, Clone, PartialOrd, Ord)]
#[derive(Debug, Clone)]
pub enum Label {
Id(u32),
Named(String),
Expand Down Expand Up @@ -415,6 +416,20 @@ impl PartialEq for Label {
}
}

impl Eq for Label {}

impl PartialOrd for Label {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl Ord for Label {
fn cmp(&self, other: &Self) -> Ordering {
self.get_id().cmp(&other.get_id())
}
}

impl std::hash::Hash for Label {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
state.write_u32(self.get_id());
Expand Down

0 comments on commit 2afc570

Please sign in to comment.