Skip to content

Commit 0c2e964

Browse files
committed
fix: fix the no_std error for HashSet
In no_std mode, BtreeMap is used instead of HashMap, but Range does not implement the `Ord` trait. In order to use HashMap in no_std mode, hashbrown crate is used here, which provides better performance than the standard library. Signed-off-by: Godones <[email protected]>
1 parent 03c7289 commit 0c2e964

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ cranelift-frontend = { version = "0.99", optional = true }
4141
cranelift-jit = { version = "0.99", optional = true }
4242
cranelift-native = { version = "0.99", optional = true }
4343
cranelift-module = { version = "0.99", optional = true }
44+
hashbrown = { version = "0.15", default-features = false, features = [
45+
"alloc",
46+
"default-hasher",
47+
] }
4448

4549
[dev-dependencies]
4650

src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub mod lib {
7171
pub use self::core::mem;
7272
pub use self::core::mem::ManuallyDrop;
7373
pub use self::core::ptr;
74+
pub use hashbrown::{HashMap,HashSet};
7475

7576
#[cfg(feature = "std")]
7677
pub use std::println;
@@ -98,9 +99,9 @@ pub mod lib {
9899
// BTree-based implementations of Maps and Sets. The cranelift module uses
99100
// BTrees by default, hence we need to expose it twice here.
100101
#[cfg(not(feature = "std"))]
101-
pub use alloc::collections::{BTreeMap as HashMap, BTreeMap, BTreeSet as HashSet, BTreeSet};
102+
pub use alloc::collections::{BTreeMap};
102103
#[cfg(feature = "std")]
103-
pub use std::collections::{BTreeMap, HashMap, HashSet};
104+
pub use std::collections::{BTreeMap};
104105

105106
/// In no_std we use a custom implementation of the error which acts as a
106107
/// replacement for the io Error.

0 commit comments

Comments
 (0)