38
38
//! ```
39
39
//!
40
40
//! If you need more control over how a value is hashed, you need to implement
41
- //! the `Hash` trait:
41
+ //! the [`Hash`] trait:
42
+ //!
43
+ //! [`Hash`]: trait.Hash.html
42
44
//!
43
45
//! ```rust
44
46
//! use std::hash::{Hash, Hasher, SipHasher};
@@ -90,21 +92,21 @@ mod sip;
90
92
/// The `H` type parameter is an abstract hash state that is used by the `Hash`
91
93
/// to compute the hash.
92
94
///
93
- /// If you are also implementing `Eq`, there is an additional property that
95
+ /// If you are also implementing [ `Eq`] , there is an additional property that
94
96
/// is important:
95
97
///
96
98
/// ```text
97
99
/// k1 == k2 -> hash(k1) == hash(k2)
98
100
/// ```
99
101
///
100
102
/// In other words, if two keys are equal, their hashes should also be equal.
101
- /// `HashMap` and `HashSet` both rely on this behavior.
103
+ /// [ `HashMap`] and [ `HashSet`] both rely on this behavior.
102
104
///
103
105
/// ## Derivable
104
106
///
105
107
/// This trait can be used with `#[derive]` if all fields implement `Hash`.
106
108
/// When `derive`d, the resulting hash will be the combination of the values
107
- /// from calling `.hash()` on each field.
109
+ /// from calling [ `.hash()`] on each field.
108
110
///
109
111
/// ## How can I implement `Hash`?
110
112
///
@@ -127,6 +129,11 @@ mod sip;
127
129
/// }
128
130
/// }
129
131
/// ```
132
+ ///
133
+ /// [`Eq`]: ../../std/cmp/trait.Eq.html
134
+ /// [`HashMap`]: ../../std/collections/struct.HashMap.html
135
+ /// [`HashSet`]: ../../std/collections/struct.HashSet.html
136
+ /// [`.hash()`]: #tymethod.hash
130
137
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
131
138
pub trait Hash {
132
139
/// Feeds this value into the state given, updating the hasher as necessary.
@@ -151,35 +158,35 @@ pub trait Hasher {
151
158
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
152
159
fn finish ( & self ) -> u64 ;
153
160
154
- /// Writes some data into this `Hasher`
161
+ /// Writes some data into this `Hasher`.
155
162
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
156
163
fn write ( & mut self , bytes : & [ u8 ] ) ;
157
164
158
- /// Write a single `u8` into this hasher
165
+ /// Write a single `u8` into this hasher.
159
166
#[ inline]
160
167
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
161
168
fn write_u8 ( & mut self , i : u8 ) {
162
169
self . write ( & [ i] )
163
170
}
164
- /// Write a single `u16` into this hasher.
171
+ /// Writes a single `u16` into this hasher.
165
172
#[ inline]
166
173
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
167
174
fn write_u16 ( & mut self , i : u16 ) {
168
175
self . write ( & unsafe { mem:: transmute :: < _ , [ u8 ; 2 ] > ( i) } )
169
176
}
170
- /// Write a single `u32` into this hasher.
177
+ /// Writes a single `u32` into this hasher.
171
178
#[ inline]
172
179
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
173
180
fn write_u32 ( & mut self , i : u32 ) {
174
181
self . write ( & unsafe { mem:: transmute :: < _ , [ u8 ; 4 ] > ( i) } )
175
182
}
176
- /// Write a single `u64` into this hasher.
183
+ /// Writes a single `u64` into this hasher.
177
184
#[ inline]
178
185
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
179
186
fn write_u64 ( & mut self , i : u64 ) {
180
187
self . write ( & unsafe { mem:: transmute :: < _ , [ u8 ; 8 ] > ( i) } )
181
188
}
182
- /// Write a single `usize` into this hasher.
189
+ /// Writes a single `usize` into this hasher.
183
190
#[ inline]
184
191
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
185
192
fn write_usize ( & mut self , i : usize ) {
@@ -189,31 +196,31 @@ pub trait Hasher {
189
196
self . write ( bytes) ;
190
197
}
191
198
192
- /// Write a single `i8` into this hasher.
199
+ /// Writes a single `i8` into this hasher.
193
200
#[ inline]
194
201
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
195
202
fn write_i8 ( & mut self , i : i8 ) {
196
203
self . write_u8 ( i as u8 )
197
204
}
198
- /// Write a single `i16` into this hasher.
205
+ /// Writes a single `i16` into this hasher.
199
206
#[ inline]
200
207
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
201
208
fn write_i16 ( & mut self , i : i16 ) {
202
209
self . write_u16 ( i as u16 )
203
210
}
204
- /// Write a single `i32` into this hasher.
211
+ /// Writes a single `i32` into this hasher.
205
212
#[ inline]
206
213
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
207
214
fn write_i32 ( & mut self , i : i32 ) {
208
215
self . write_u32 ( i as u32 )
209
216
}
210
- /// Write a single `i64` into this hasher.
217
+ /// Writes a single `i64` into this hasher.
211
218
#[ inline]
212
219
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
213
220
fn write_i64 ( & mut self , i : i64 ) {
214
221
self . write_u64 ( i as u64 )
215
222
}
216
- /// Write a single `isize` into this hasher.
223
+ /// Writes a single `isize` into this hasher.
217
224
#[ inline]
218
225
#[ stable( feature = "hasher_write" , since = "1.3.0" ) ]
219
226
fn write_isize ( & mut self , i : isize ) {
0 commit comments