Skip to content

Commit 369ad20

Browse files
committed
Replace "ahash" with "default-hasher" in Cargo features
This allows us to change the default hasher in the future without it being a breaking change.
1 parent 65c553d commit 369ad20

File tree

4 files changed

+25
-15
lines changed

4 files changed

+25
-15
lines changed

Cargo.toml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ serde = { version = "1.0.25", default-features = false, optional = true }
2222
rkyv = { version = "0.7.42", optional = true, default-features = false, features = [
2323
"alloc",
2424
] }
25+
borsh = { version = "1.5.0", default-features = false, optional = true, features = ["derive"]}
2526

2627
# When built as part of libstd
2728
core = { version = "1.0.0", optional = true, package = "rustc-std-workspace-core" }
@@ -36,9 +37,6 @@ allocator-api2 = { version = "0.2.9", optional = true, default-features = false,
3637
# Equivalent trait which can be shared with other hash table implementations.
3738
equivalent = { version = "1.0", optional = true, default-features = false }
3839

39-
# borsh serde
40-
borsh = { version = "1.5.0", default-features = false, optional = true, features = ["derive"]}
41-
4240
[dev-dependencies]
4341
lazy_static = "1.4"
4442
rand = { version = "0.8.3", features = ["small_rng"] }
@@ -50,27 +48,37 @@ bumpalo = { version = "3.13.0", features = ["allocator-api2"] }
5048
rkyv = { version = "0.7.42", features = ["validation"] }
5149

5250
[features]
53-
default = ["ahash", "inline-more", "allocator-api2", "equivalent"]
51+
default = ["default-hasher", "inline-more", "allocator-api2", "equivalent"]
5452

53+
# Enables use of nightly features. This is only guaranteed to work on the latest
54+
# version of nightly Rust.
5555
nightly = ["allocator-api2?/nightly", "bumpalo/allocator_api"]
5656

57+
# Enables the RustcEntry API used to provide the standard library's Entry API.
5758
rustc-internal-api = []
59+
60+
# Internal feature used when building as part of the standard library.
5861
rustc-dep-of-std = [
5962
"nightly",
6063
"core",
6164
"compiler_builtins",
6265
"alloc",
6366
"rustc-internal-api",
6467
]
68+
69+
# Enables the RawTable API.
6570
raw = []
6671

72+
# Provides a default hasher. Currently this is AHash but this is subject to
73+
# change in the future. Note that the default hasher does *not* provide HashDoS
74+
# resistance, unlike the one in the standard library.
75+
default-hasher = ["dep:ahash"]
76+
6777
# Enables usage of `#[inline]` on far more functions than by default in this
6878
# crate. This may lead to a performance increase but often comes at a compile
6979
# time cost.
7080
inline-more = []
7181

72-
borsh = ["dep:borsh"]
73-
7482
[package.metadata.docs.rs]
7583
features = ["nightly", "rayon", "serde", "raw"]
7684
rustdoc-args = ["--generate-link-to-definition"]

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@ This crate has the following Cargo features:
101101

102102
- `nightly`: Enables nightly-only features including: `#[may_dangle]`.
103103
- `serde`: Enables serde serialization support.
104+
- `borsh`: Enables borsh serialization support.
104105
- `rkyv`: Enables rkyv serialization support.
105106
- `rayon`: Enables rayon parallel iterator support.
107+
- `equivalent`: Allows comparisons to be customized with the `Equivalent` trait.
106108
- `raw`: Enables access to the experimental and unsafe `RawTable` API.
107109
- `inline-more`: Adds inline hints to most functions, improving run-time performance at the cost
108110
of compilation time. (enabled by default)
109-
- `ahash`: Compiles with ahash as default hasher. (enabled by default)
111+
- `default-hasher`: Compiles with ahash as default hasher. (enabled by default)
110112
- `allocator-api2`: Enables support for allocators that support `allocator-api2`. (enabled by default)
111113

112114
## License

src/map.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ use core::mem;
1111
use core::ops::Index;
1212

1313
/// Default hasher for `HashMap`.
14-
#[cfg(feature = "ahash")]
14+
#[cfg(feature = "default-hasher")]
1515
pub type DefaultHashBuilder = core::hash::BuildHasherDefault<ahash::AHasher>;
1616

1717
/// Dummy default hasher for `HashMap`.
18-
#[cfg(not(feature = "ahash"))]
18+
#[cfg(not(feature = "default-hasher"))]
1919
pub enum DefaultHashBuilder {}
2020

2121
/// A hash map implemented with quadratic probing and SIMD lookup.
@@ -262,7 +262,7 @@ where
262262
hash_builder.hash_one(val)
263263
}
264264

265-
#[cfg(feature = "ahash")]
265+
#[cfg(feature = "default-hasher")]
266266
impl<K, V> HashMap<K, V, DefaultHashBuilder> {
267267
/// Creates an empty `HashMap`.
268268
///
@@ -325,7 +325,7 @@ impl<K, V> HashMap<K, V, DefaultHashBuilder> {
325325
}
326326
}
327327

328-
#[cfg(feature = "ahash")]
328+
#[cfg(feature = "default-hasher")]
329329
impl<K, V, A: Allocator> HashMap<K, V, DefaultHashBuilder, A> {
330330
/// Creates an empty `HashMap` using the given allocator.
331331
///
@@ -2258,7 +2258,7 @@ where
22582258
}
22592259

22602260
// The default hasher is used to match the std implementation signature
2261-
#[cfg(feature = "ahash")]
2261+
#[cfg(feature = "default-hasher")]
22622262
impl<K, V, A, const N: usize> From<[(K, V); N]> for HashMap<K, V, DefaultHashBuilder, A>
22632263
where
22642264
K: Eq + Hash,

src/set.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ impl<T: Clone, S: Clone, A: Allocator + Clone> Clone for HashSet<T, S, A> {
128128
}
129129
}
130130

131-
#[cfg(feature = "ahash")]
131+
#[cfg(feature = "default-hasher")]
132132
impl<T> HashSet<T, DefaultHashBuilder> {
133133
/// Creates an empty `HashSet`.
134134
///
@@ -192,7 +192,7 @@ impl<T> HashSet<T, DefaultHashBuilder> {
192192
}
193193
}
194194

195-
#[cfg(feature = "ahash")]
195+
#[cfg(feature = "default-hasher")]
196196
impl<T: Hash + Eq, A: Allocator> HashSet<T, DefaultHashBuilder, A> {
197197
/// Creates an empty `HashSet`.
198198
///
@@ -1324,7 +1324,7 @@ where
13241324
}
13251325

13261326
// The default hasher is used to match the std implementation signature
1327-
#[cfg(feature = "ahash")]
1327+
#[cfg(feature = "default-hasher")]
13281328
impl<T, A, const N: usize> From<[T; N]> for HashSet<T, DefaultHashBuilder, A>
13291329
where
13301330
T: Eq + Hash,

0 commit comments

Comments
 (0)