Skip to content

Commit 5cc056a

Browse files
committed
A few improvements to the core::hash top-level docs.
Primarily opened to address the concerns brought up in #40498. * run rustfmt on code blocks * use `DefaultHasher` instead of deprecated `SipHasher` * rename `hash` to `calculate_hash` to prevent confusion with the `hash` method
1 parent fd182c4 commit 5cc056a

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

src/libcore/hash/mod.rs

+31-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
//! # Examples
1717
//!
1818
//! ```rust
19-
//! use std::hash::{Hash, SipHasher, Hasher};
19+
//! use std::collections::hash_map::DefaultHasher;
20+
//! use std::hash::{Hash, Hasher};
2021
//!
2122
//! #[derive(Hash)]
2223
//! struct Person {
@@ -25,13 +26,21 @@
2526
//! phone: u64,
2627
//! }
2728
//!
28-
//! let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 };
29-
//! let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 };
29+
//! let person1 = Person {
30+
//! id: 5,
31+
//! name: "Janet".to_string(),
32+
//! phone: 555_666_7777,
33+
//! };
34+
//! let person2 = Person {
35+
//! id: 5,
36+
//! name: "Bob".to_string(),
37+
//! phone: 555_666_7777,
38+
//! };
3039
//!
31-
//! assert!(hash(&person1) != hash(&person2));
40+
//! assert!(calculate_hash(&person1) != calculate_hash(&person2));
3241
//!
33-
//! fn hash<T: Hash>(t: &T) -> u64 {
34-
//! let mut s = SipHasher::new();
42+
//! fn calculate_hash<T: Hash>(t: &T) -> u64 {
43+
//! let mut s = DefaultHasher::new();
3544
//! t.hash(&mut s);
3645
//! s.finish()
3746
//! }
@@ -43,11 +52,12 @@
4352
//! [`Hash`]: trait.Hash.html
4453
//!
4554
//! ```rust
46-
//! use std::hash::{Hash, Hasher, SipHasher};
55+
//! use std::collections::hash_map::DefaultHasher;
56+
//! use std::hash::{Hash, Hasher};
4757
//!
4858
//! struct Person {
4959
//! id: u32,
50-
//! # #[allow(dead_code)]
60+
//! # #[allow(dead_code)]
5161
//! name: String,
5262
//! phone: u64,
5363
//! }
@@ -59,13 +69,21 @@
5969
//! }
6070
//! }
6171
//!
62-
//! let person1 = Person { id: 5, name: "Janet".to_string(), phone: 555_666_7777 };
63-
//! let person2 = Person { id: 5, name: "Bob".to_string(), phone: 555_666_7777 };
72+
//! let person1 = Person {
73+
//! id: 5,
74+
//! name: "Janet".to_string(),
75+
//! phone: 555_666_7777,
76+
//! };
77+
//! let person2 = Person {
78+
//! id: 5,
79+
//! name: "Bob".to_string(),
80+
//! phone: 555_666_7777,
81+
//! };
6482
//!
65-
//! assert_eq!(hash(&person1), hash(&person2));
83+
//! assert_eq!(calculate_hash(&person1), calculate_hash(&person2));
6684
//!
67-
//! fn hash<T: Hash>(t: &T) -> u64 {
68-
//! let mut s = SipHasher::new();
85+
//! fn calculate_hash<T: Hash>(t: &T) -> u64 {
86+
//! let mut s = DefaultHasher::new();
6987
//! t.hash(&mut s);
7088
//! s.finish()
7189
//! }

0 commit comments

Comments
 (0)