Skip to content

Commit

Permalink
Use rustversion to add compatibility with older rustc versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogxd committed May 27, 2024
1 parent 0428f43 commit d8aed65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 8 additions & 1 deletion src/hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d8aed65

Please sign in to comment.