Skip to content

Commit b876655

Browse files
committed
lib.rs: add example
This is adapted from the example in std::hash.
1 parent 1793700 commit b876655

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
@@ -38,6 +38,38 @@
3838
//!
3939
//! This crate is guaranteed to compile on latest stable Rust. It *might* compile on older
4040
//! versions but that may change in any new patch release.
41+
//!
42+
//! # Examples
43+
//!
44+
//! ```
45+
//! use hash32::{FnvHasher, Hasher as _};
46+
//!
47+
//! #[derive(Hash)]
48+
//! struct Person {
49+
//! id: u32,
50+
//! name: &'static str,
51+
//! phone: u64,
52+
//! }
53+
//!
54+
//! let person1 = Person {
55+
//! id: 5,
56+
//! name: "Janet",
57+
//! phone: 555_666_7777,
58+
//! };
59+
//! let person2 = Person {
60+
//! id: 5,
61+
//! name: "Bob",
62+
//! phone: 555_666_7777,
63+
//! };
64+
//!
65+
//! assert!(calculate_hash(&person1) != calculate_hash(&person2));
66+
//!
67+
//! fn calculate_hash<T: core::hash::Hash>(t: &T) -> u32 {
68+
//! let mut fnv: FnvHasher = Default::default();
69+
//! t.hash(&mut fnv);
70+
//! fnv.finish32()
71+
//! }
72+
//! ```
4173
4274
#![warn(
4375
missing_docs,

0 commit comments

Comments
 (0)