File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,3 +7,7 @@ license = "Apache-2.0/MIT"
77readme = " README.md"
88keywords = [" hash" , " fxhash" , " rustc" ]
99repository = " https://github.com/rust-lang-nursery/rustc-hash"
10+
11+ [features ]
12+ std = []
13+ default = [" std" ]
Original file line number Diff line number Diff line change @@ -24,3 +24,15 @@ use rustc_hash::FxHashMap;
2424let mut map : FxHashMap <u32 , u32 > = FxHashMap :: default ();
2525map . insert (22 , 44 );
2626```
27+
28+ ### ` no_std `
29+
30+ This crate can be used as a ` no_std ` crate by disabling the ` std `
31+ feature, which is on by default, as follows:
32+
33+ ``` toml
34+ rustc-hash = { version = " 1.0" , default-features = false }
35+ ```
36+
37+ In this configuration, ` FxHasher ` is the only export, and the
38+ ` FxHashMap ` /` FxHashSet ` type aliases are omitted.
Original file line number Diff line number Diff line change 1313//! # Example
1414//!
1515//! ```rust
16+ //! # #[cfg(feature = "std")]
17+ //! # fn main() {
1618//! use rustc_hash::FxHashMap;
1719//! let mut map: FxHashMap<u32, u32> = FxHashMap::default();
1820//! map.insert(22, 44);
21+ //! # }
22+ //! # #[cfg(not(feature = "std"))]
23+ //! # fn main() { }
1924//! ```
2025
26+ #![ no_std]
27+
28+ #[ cfg( feature = "std" ) ]
29+ extern crate std;
30+
31+ use core:: convert:: TryInto ;
32+ use core:: default:: Default ;
33+ #[ cfg( feature = "std" ) ]
34+ use core:: hash:: BuildHasherDefault ;
35+ use core:: hash:: Hasher ;
36+ use core:: mem:: size_of;
37+ use core:: ops:: BitXor ;
38+ #[ cfg( feature = "std" ) ]
2139use std:: collections:: { HashMap , HashSet } ;
22- use std:: convert:: TryInto ;
23- use std:: default:: Default ;
24- use std:: hash:: { Hasher , BuildHasherDefault } ;
25- use std:: ops:: BitXor ;
26- use std:: mem:: size_of;
2740
2841/// Type alias for a hashmap using the `fx` hash algorithm.
42+ #[ cfg( feature = "std" ) ]
2943pub type FxHashMap < K , V > = HashMap < K , V , BuildHasherDefault < FxHasher > > ;
3044
3145/// Type alias for a hashmap using the `fx` hash algorithm.
46+ #[ cfg( feature = "std" ) ]
3247pub type FxHashSet < V > = HashSet < V , BuildHasherDefault < FxHasher > > ;
3348
3449/// A speedy hash algorithm for use within rustc. The hashmap in liballoc
@@ -43,7 +58,7 @@ pub type FxHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;
4358/// similar or slightly worse than FNV, but the speed of the hash function
4459/// itself is much higher because it works on up to 8 bytes at a time.
4560pub struct FxHasher {
46- hash : usize
61+ hash : usize ,
4762}
4863
4964#[ cfg( target_pointer_width = "32" ) ]
You can’t perform that action at this time.
0 commit comments