Skip to content

Commit

Permalink
Derive Clone for FxRandomState
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Sep 25, 2024
1 parent eb049a8 commit 9f847bb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/random_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub type FxHashSetRand<V> = HashSet<V, FxRandomState>;
/// 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,
}
Expand Down Expand Up @@ -62,6 +63,15 @@ mod tests {

use crate::FxHashMapRand;

#[test]
fn cloned_random_states_are_equal() {
// The standard library's `RandomState` does this, so we should too.
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();
Expand Down

0 comments on commit 9f847bb

Please sign in to comment.