Skip to content

Commit c5e0e53

Browse files
newAMeldruin
authored andcommitted
Hashers: Add examples
1 parent 4543c42 commit c5e0e53

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/fnv.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ const PRIME: u32 = 0x1000193;
88
/// Specifically this implements the [FNV-1a hash].
99
///
1010
/// [FNV-1a hash]: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash
11+
///
12+
/// # Examples
13+
///
14+
/// ```
15+
/// use core::hash::Hasher as _;
16+
/// use hash32::{FnvHasher, Hasher as _};
17+
///
18+
/// let mut hasher: FnvHasher = Default::default();
19+
/// hasher.write(b"Hello, World!");
20+
///
21+
/// println!("Hash is {:x}!", hasher.finish32());
22+
/// ```
1123
#[derive(Debug, Clone)]
1224
pub struct FnvHasher {
1325
state: u32,

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ mod murmur3;
8686
/// # Examples
8787
///
8888
/// ```
89-
/// use core::hash::{Hasher as _};
89+
/// use core::hash::Hasher as _;
9090
/// use hash32::{FnvHasher, Hasher as _};
9191
///
9292
/// let mut hasher: FnvHasher = Default::default();

src/murmur3.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ use core::slice;
44
use crate::Hasher as _;
55

66
/// 32-bit `MurmurHash3` hasher
7+
///
8+
/// # Examples
9+
///
10+
/// ```
11+
/// use core::hash::Hasher as _;
12+
/// use hash32::{Hasher as _, Murmur3Hasher};
13+
///
14+
/// let mut hasher: Murmur3Hasher = Default::default();
15+
/// hasher.write(b"Hello, World!");
16+
///
17+
/// println!("Hash is {:x}!", hasher.finish32());
18+
/// ```
719
#[derive(Debug, Clone)]
820
pub struct Murmur3Hasher {
921
buf: Buffer,

0 commit comments

Comments
 (0)