shepmaster / twox-hash

A Rust implementation of the XXHash algorithm.
MIT License
361 stars 41 forks source link

Provide option to avoid importing `rand` crate when not required #71

Open satyarohith opened 3 years ago

satyarohith commented 3 years ago

Please correct me if my assumption is wrong. The rand crate is used for RandomXxHashBuilder64 and friends but is probably not required when using the std builder.

The below code also pulls in rand as a dependency. It would be nice to have something like the features = ["xxhash64"] option to avoid pulling rand.

use std::hash::BuildHasher;
use std::hash::BuildHasherDefault;
use std::hash::Hasher;
use twox_hash::XxHash64;

fn main() {
    let mut hasher = BuildHasherDefault::<XxHash64>::default().build_hasher();
    hasher.write(b"hello world");

    println!("Hello, world!");
}
shepmaster commented 3 years ago

Can you try disabling the std feature?

Your code example compiles with:

[dependencies]
twox-hash = { version = "1.6.1", default-features = false }
% cargo tree
example v0.1.0 (/private/tmp/example)
└── twox-hash v1.6.1
    ├── cfg-if v1.0.0
    └── static_assertions v1.1.0