diff --git a/src/random_state.rs b/src/random_state.rs index b70ba4d..c8c35a0 100644 --- a/src/random_state.rs +++ b/src/random_state.rs @@ -13,6 +13,7 @@ pub type FxHashSetRand = HashSet; /// A particular instance `FxRandomState` will create the same instances of /// [`Hasher`], but the hashers created by two different `FxRandomState` /// instances are unlikely to produce the same result for the same values. +#[derive(Clone)] pub struct FxRandomState { seed: usize, } @@ -62,6 +63,14 @@ mod tests { use crate::FxHashMapRand; + #[test] + fn cloned_random_states_are_equal() { + let a = FxHashMapRand::<&str, u32>::default(); + let b = a.clone(); + + assert_eq!(a.hasher().seed, b.hasher().seed); + } + #[test] fn random_states_are_different() { let a = FxHashMapRand::<&str, u32>::default(); diff --git a/src/seeded_state.rs b/src/seeded_state.rs index 30efd27..e841906 100644 --- a/src/seeded_state.rs +++ b/src/seeded_state.rs @@ -18,6 +18,7 @@ pub type FxHashSetSeed = std::collections::HashSet; /// map.insert(15, 610); /// assert_eq!(map[&15], 610); /// ``` +#[derive(Clone)] pub struct FxSeededState { seed: usize, } @@ -43,6 +44,18 @@ mod tests { use crate::FxSeededState; + #[test] + fn cloned_seeded_states_are_equal() { + let seed = 2; + let a = FxSeededState::with_seed(seed); + let b = a.clone(); + + assert_eq!(a.seed, b.seed); + assert_eq!(a.seed, seed); + + assert_eq!(a.build_hasher().hash, b.build_hasher().hash); + } + #[test] fn same_seed_produces_same_hasher() { let seed = 1;