@@ -175,6 +175,21 @@ pub trait Hash {
175
175
176
176
/// Feeds a slice of this type into the given [`Hasher`].
177
177
///
178
+ /// This method is meant as a convenience, but its implementation is
179
+ /// also explicitly left unspecified. It isn't guaranteed to be
180
+ /// equivalent to repeated calls of [`hash`] and implementations of
181
+ /// [`Hash`] should keep that in mind and call [`hash`] themselves
182
+ /// if the slice isn't treated as a whole unit in the [`PartialEq`]
183
+ /// implementation.
184
+ ///
185
+ /// For example, a [`VecDeque`] implementation might naïvely call
186
+ /// [`as_slices`] and then [`hash_slice`] on each slice, but this
187
+ /// is wrong since the two slices can change with a call to
188
+ /// [`make_contiguous`] without affecting the [`PartialEq`]
189
+ /// result. Since these slices aren't treated as singular
190
+ /// units, and instead part of a larger deque, this method cannot
191
+ /// be used.
192
+ ///
178
193
/// # Examples
179
194
///
180
195
/// ```
@@ -186,6 +201,12 @@ pub trait Hash {
186
201
/// Hash::hash_slice(&numbers, &mut hasher);
187
202
/// println!("Hash is {:x}!", hasher.finish());
188
203
/// ```
204
+ ///
205
+ /// [`VecDeque`]: ../../std/collections/struct.VecDeque.html
206
+ /// [`as_slices`]: ../../std/collections/struct.VecDeque.html#method.as_slices
207
+ /// [`make_contiguous`]: ../../std/collections/struct.VecDeque.html#method.make_contiguous
208
+ /// [`hash`]: Hash::hash
209
+ /// [`hash_slice`]: Hash::hash_slice
189
210
#[ stable( feature = "hash_slice" , since = "1.3.0" ) ]
190
211
fn hash_slice < H : Hasher > ( data : & [ Self ] , state : & mut H )
191
212
where
@@ -221,6 +242,11 @@ pub use macros::Hash;
221
242
/// instance (with [`write`] and [`write_u8`] etc.). Most of the time, `Hasher`
222
243
/// instances are used in conjunction with the [`Hash`] trait.
223
244
///
245
+ /// This trait makes no assumptions about how the various `write_*` methods are
246
+ /// defined and implementations of [`Hash`] should not assume that they work one
247
+ /// way or another. You cannot assume, for example, that a [`write_u32`] call is
248
+ /// equivalent to four calls of [`write_u8`].
249
+ ///
224
250
/// # Examples
225
251
///
226
252
/// ```
@@ -240,6 +266,7 @@ pub use macros::Hash;
240
266
/// [`finish`]: Hasher::finish
241
267
/// [`write`]: Hasher::write
242
268
/// [`write_u8`]: Hasher::write_u8
269
+ /// [`write_u32`]: Hasher::write_u32
243
270
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
244
271
pub trait Hasher {
245
272
/// Returns the hash value for the values written so far.
0 commit comments