Skip to content

Commit 26b433a

Browse files
authored
wasmtime-slab: add PartialOrd and Ord to Ids. (#10568)
This became necessary in a use-case where I am using slab IDs as keys in a BTreeMap (as a member of a tuple key type). The actual ordering doesn't carry a fundamental meaning, but overall I do need ordering as the first elements of the tuple have significant ordering and I need to process in order (namely: timer deadlines). The slab ID ordering is at least stable (since the Ids are integers under the hood), and this is useful for anyone who needs to build an ordered key type. The alternative is to use `.into_raw()` and manually write an `Ord` impl or use the raw `u32` in a key, which is much worse.
1 parent b1be235 commit 26b433a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/slab/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ use core::fmt;
131131
use core::num::NonZeroU32;
132132

133133
/// An identifier for an allocated value inside a `slab`.
134-
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
134+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
135135
#[repr(transparent)]
136136
pub struct Id(EntryIndex);
137137

@@ -193,7 +193,7 @@ enum Entry<T> {
193193
},
194194
}
195195

196-
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
196+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
197197
#[repr(transparent)]
198198
struct EntryIndex(NonZeroU32);
199199

0 commit comments

Comments
 (0)