Skip to content

Commit 1c85035

Browse files
authored
Merge pull request #41 from xermicus/fix-nostd
Bugfix: fix no_std builds
2 parents 0773e83 + 38d9373 commit 1c85035

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ pub type FxHashSet<V> = HashSet<V, FxBuildHasher>;
4646
#[cfg(feature = "rand")]
4747
pub use random_state::{FxHashMapRand, FxHashSetRand, FxRandomState};
4848

49-
pub use seeded_state::{FxHashMapSeed, FxHashSetSeed, FxSeededState};
49+
pub use seeded_state::FxSeededState;
50+
#[cfg(feature = "std")]
51+
pub use seeded_state::{FxHashMapSeed, FxHashSetSeed};
5052

5153
/// A speedy hash algorithm for use within rustc. The hashmap in liballoc
5254
/// by default uses SipHash which isn't quite as speedy as we want. In the

src/seeded_state.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use std::collections::{HashMap, HashSet};
2-
31
use crate::FxHasher;
42

53
/// Type alias for a hashmap using the `fx` hash algorithm with [`FxSeededState`].
6-
pub type FxHashMapSeed<K, V> = HashMap<K, V, FxSeededState>;
4+
#[cfg(feature = "std")]
5+
pub type FxHashMapSeed<K, V> = std::collections::HashMap<K, V, FxSeededState>;
76

87
/// Type alias for a hashmap using the `fx` hash algorithm with [`FxSeededState`].
9-
pub type FxHashSetSeed<V> = HashSet<V, FxSeededState>;
8+
#[cfg(feature = "std")]
9+
pub type FxHashSetSeed<V> = std::collections::HashSet<V, FxSeededState>;
1010

1111
/// [`FxSetState`] is an alternative state for `HashMap` types, allowing to use [`FxHasher`] with a set seed.
1212
///
@@ -41,16 +41,13 @@ impl core::hash::BuildHasher for FxSeededState {
4141
mod tests {
4242
use core::hash::BuildHasher;
4343

44-
use crate::{FxHashMapSeed, FxSeededState};
44+
use crate::FxSeededState;
4545

4646
#[test]
4747
fn different_states_are_different() {
48-
let a = FxHashMapSeed::<&str, u32>::with_hasher(FxSeededState::with_seed(1));
49-
let b = FxHashMapSeed::<&str, u32>::with_hasher(FxSeededState::with_seed(2));
48+
let a = FxSeededState::with_seed(1);
49+
let b = FxSeededState::with_seed(2);
5050

51-
assert_ne!(
52-
a.hasher().build_hasher().hash,
53-
b.hasher().build_hasher().hash
54-
);
51+
assert_ne!(a.build_hasher().hash, b.build_hasher().hash);
5552
}
5653
}

0 commit comments

Comments
 (0)