]> git.lizzy.rs Git - rust.git/blobdiff - library/alloc/src/vec/mod.rs
Rollup merge of #86140 - scottmcm:array-hash-facepalm, r=kennytm
[rust.git] / library / alloc / src / vec / mod.rs
index 4a1d564e2ab879547f8036133d7c0dc296c34c70..b59d2977add95ffb5fd45109940ac8a14eea1ff6 100644 (file)
@@ -2407,6 +2407,23 @@ fn clone_from(&mut self, other: &Self) {
     }
 }
 
+/// The hash of a vector is the same as that of the corresponding slice,
+/// as required by the `core::borrow::Borrow` implementation.
+///
+/// ```
+/// use std::hash::{BuildHasher, Hash, Hasher};
+///
+/// fn hash_of(x: impl Hash, b: &impl BuildHasher) -> u64 {
+///     let mut h = b.build_hasher();
+///     x.hash(&mut h);
+///     h.finish()
+/// }
+///
+/// let b = std::collections::hash_map::RandomState::new();
+/// let v: Vec<u8> = vec![0xa8, 0x3c, 0x09];
+/// let s: &[u8] = &[0xa8, 0x3c, 0x09];
+/// assert_eq!(hash_of(v, &b), hash_of(s, &b));
+/// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Hash, A: Allocator> Hash for Vec<T, A> {
     #[inline]