Skip to content

Commit 4543c42

Browse files
newAMeldruin
authored andcommitted
lib.rs: doc: rework
I reworked the main docstring to: - Clairify subjects - Add code links - Add advice for picking a specific hasher - Add security notes
1 parent e074899 commit 4543c42

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

src/lib.rs

+29-10
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@
88
//!
99
//! # Relationship to `core::hash`
1010
//!
11-
//! This crate extends [`core::hash`] with a 32-bit version of `Hasher`, which extends
12-
//! `core::hash::Hasher`. It requires that the hasher only performs 32-bit operations when computing
13-
//! the hash, and adds [`finish32`] to get the hasher's result as a `u32`. The standard `finish`
14-
//! method should just zero-extend this result.
11+
//! This crate extends [`core::hash::Hasher`] with a 32-bit version, [`hash32::Hasher`].
1512
//!
16-
//! Since it extends `core::hash::Hasher`, `Hasher` can be used with any type which implements the
17-
//! standard `Hash` trait.
13+
//! The [`hash32::Hasher`] trait requires the hasher to perform only 32-bit operations when
14+
//! computing the hash.
15+
//! The trait method [`hash32::Hasher::finish32`] returns the hasher's result as a `u32`.
16+
//! The [`core::hash::Hasher::finish`] method zero-extends the [`hash32::Hasher::finish32`]
17+
//! result to a `u64`.
1818
//!
19+
//! Since [`hash32::Hasher`] extends [`core::hash::Hasher`], the [`hash32::Hasher`] trait can be
20+
//! used with any type which implements the [`core::hash::Hash`] trait.
21+
//!
22+
//! [`hash32::Hasher`]: crate::Hasher
23+
//! [`hash32::Hasher::finish32`]: crate::Hasher::finish32
1924
//! [`core::hash`]: https://doc.rust-lang.org/std/hash/index.html
2025
//! [`finish32`]: crate::Hasher::finish32
2126
//!
@@ -26,13 +31,27 @@
2631
//! - [`FnvHasher`] Fowler-Noll-Vo 1a
2732
//! - [`Murmur3Hasher`] `MurmurHash3`
2833
//!
34+
//! ## Picking a hasher
35+
//!
36+
//! - [`FnvHasher`] is faster and consumes less code space than [`Murmur3Hasher`].
37+
//! - [`Murmur3Hasher`] offers better collision resistance than [`FnvHasher`].
38+
//!
39+
//! ## Security
40+
//!
41+
//! Hashers provided by this crate are not cryptographically secure, and must **not** be used
42+
//! for security purposes.
43+
//! Additionally, unlike [`std::hash::DefaultHasher`] the provided hash algorithms lack
44+
//! denial-of-service protection, and must only be used with trusted data.
45+
//!
2946
//! # Generic code
3047
//!
31-
//! In generic code, the trait bound `H: core::hash::Hasher` accepts *both* 64-bit hashers like
32-
//! `std::collections::hash_map::DefaultHasher`; and 32-bit hashers like the ones defined in this
33-
//! crate (`hash32::FnvHasher` and `hash32::Murmur3Hasher`)
48+
//! In generic code, the trait bound `H: core::hash::Hasher` accepts **both** 64-bit hashers such
49+
//! as [`std::hash::DefaultHasher`]; and 32-bit hashers such as the ones defined in this crate,
50+
//! [`FnvHasher`], and [`Murmur3Hasher`].
51+
//!
52+
//! The trait bound `H: hash32::Hasher` is **more** restrictive as it only accepts 32-bit hashers.
3453
//!
35-
//! The trait bound `H: hash32::Hasher` is *more* restrictive as it only accepts 32-bit hashers.
54+
//! [`std::hash::DefaultHasher`]: https://doc.rust-lang.org/std/hash/struct.DefaultHasher.html
3655
//!
3756
//! # MSRV
3857
//!

0 commit comments

Comments
 (0)