///
/// ```
/// let mut vec = Vec::with_capacity(10);
- /// vec.extend([1, 2, 3].iter().cloned());
+ /// vec.extend([1, 2, 3]);
/// assert_eq!(vec.capacity(), 10);
/// vec.shrink_to_fit();
/// assert!(vec.capacity() >= 3);
/// ```
/// #![feature(shrink_to)]
/// let mut vec = Vec::with_capacity(10);
- /// vec.extend([1, 2, 3].iter().cloned());
+ /// vec.extend([1, 2, 3]);
/// assert_eq!(vec.capacity(), 10);
/// vec.shrink_to(4);
/// assert!(vec.capacity() >= 4);
///
/// ```
/// let mut vec = Vec::with_capacity(10);
- /// vec.extend([1, 2, 3].iter().cloned());
+ /// vec.extend([1, 2, 3]);
///
/// assert_eq!(vec.capacity(), 10);
/// let slice = vec.into_boxed_slice();
}
}
+/// 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]
/// ```
/// let mut v = vec![1, 2, 3];
/// let new = [7, 8];
- /// let u: Vec<_> = v.splice(..2, new.iter().cloned()).collect();
+ /// let u: Vec<_> = v.splice(..2, new).collect();
/// assert_eq!(v, &[7, 8, 3]);
/// assert_eq!(u, &[1, 2]);
/// ```