Skip to content

Commit 38289fb

Browse files
newAMeldruin
authored andcommitted
lib.rs: add example
This is adapted from the example in std::hash.
1 parent c5e0e53 commit 38289fb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,38 @@
5757
//!
5858
//! This crate is guaranteed to compile on latest stable Rust. It *might* compile on older
5959
//! versions but that may change in any new patch release.
60+
//!
61+
//! # Examples
62+
//!
63+
//! ```
64+
//! use hash32::{FnvHasher, Hasher as _};
65+
//!
66+
//! #[derive(Hash)]
67+
//! struct Person {
68+
//! id: u32,
69+
//! name: &'static str,
70+
//! phone: u64,
71+
//! }
72+
//!
73+
//! let person1 = Person {
74+
//! id: 5,
75+
//! name: "Janet",
76+
//! phone: 555_666_7777,
77+
//! };
78+
//! let person2 = Person {
79+
//! id: 5,
80+
//! name: "Bob",
81+
//! phone: 555_666_7777,
82+
//! };
83+
//!
84+
//! assert!(calculate_hash(&person1) != calculate_hash(&person2));
85+
//!
86+
//! fn calculate_hash<T: core::hash::Hash>(t: &T) -> u32 {
87+
//! let mut fnv: FnvHasher = Default::default();
88+
//! t.hash(&mut fnv);
89+
//! fnv.finish32()
90+
//! }
91+
//! ```
6092
6193
#![warn(
6294
missing_docs,

0 commit comments

Comments
 (0)