From d8aed659e199e726539dad74d65811db9a148049 Mon Sep 17 00:00:00 2001 From: Olivier Giniaux Date: Mon, 27 May 2024 22:22:10 +0200 Subject: [PATCH] Use rustversion to add compatibility with older rustc versions --- Cargo.toml | 2 +- src/hasher.rs | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ea1fce6..8a2b686 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ bench-plot = [] hybrid = [] [dependencies] -# No dependencies! +rustversion = "1.0" # Compile-time cfg based on rustc version for compatibility [dev-dependencies] rand = "0.8" diff --git a/src/hasher.rs b/src/hasher.rs index 2254722..8867ca3 100644 --- a/src/hasher.rs +++ b/src/hasher.rs @@ -132,10 +132,17 @@ impl Hasher for GxHasher { #[derive(Clone, Debug)] pub struct GxBuildHasher(State); +#[rustversion::before(1.76)] +use std::collections::hash_map::RandomState; + +#[rustversion::since(1.76)] +use std::hash::RandomState; + impl Default for GxBuildHasher { #[inline] fn default() -> GxBuildHasher { - let random_state = std::hash::RandomState::new(); + + let random_state = RandomState::new(); unsafe { let state: State = std::mem::transmute(random_state); GxBuildHasher(state)