diff options
Diffstat (limited to 'src/libcollections/vec.rs')
| -rw-r--r-- | src/libcollections/vec.rs | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 8c1f98bbd07..89b1b99cfa3 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -739,17 +739,13 @@ impl<T> Vec<T> { /// # Examples /// /// ``` - /// #![feature(drain)] - /// /// // Draining using `..` clears the whole vector. /// let mut v = vec![1, 2, 3]; /// let u: Vec<_> = v.drain(..).collect(); /// assert_eq!(v, &[]); /// assert_eq!(u, &[1, 2, 3]); /// ``` - #[unstable(feature = "drain", - reason = "recently added, matches RFC", - issue = "27711")] + #[stable(feature = "drain", since = "1.6.0")] pub fn drain<R>(&mut self, range: R) -> Drain<T> where R: RangeArgument<usize> { @@ -933,6 +929,7 @@ impl<T: Clone> Vec<T> { /// /// ``` /// #![feature(vec_push_all)] + /// #![allow(deprecated)] /// /// let mut vec = vec![1]; /// vec.push_all(&[2, 3, 4]); @@ -942,7 +939,31 @@ impl<T: Clone> Vec<T> { #[unstable(feature = "vec_push_all", reason = "likely to be replaced by a more optimized extend", issue = "27744")] + #[rustc_deprecated(reason = "renamed to extend_from_slice", + since = "1.6.0")] pub fn push_all(&mut self, other: &[T]) { + self.extend_from_slice(other) + } + + /// Appends all elements in a slice to the `Vec`. + /// + /// Iterates over the slice `other`, clones each element, and then appends + /// it to this `Vec`. The `other` vector is traversed in-order. + /// + /// Note that this function is same as `extend` except that it is + /// specialized to work with slices instead. If and when Rust gets + /// specialization this function will likely be deprecated (but still + /// available). + /// + /// # Examples + /// + /// ``` + /// let mut vec = vec![1]; + /// vec.extend_from_slice(&[2, 3, 4]); + /// assert_eq!(vec, [1, 2, 3, 4]); + /// ``` + #[stable(feature = "vec_extend_from_slice", since = "1.6.0")] + pub fn extend_from_slice(&mut self, other: &[T]) { self.reserve(other.len()); for i in 0..other.len() { @@ -1103,7 +1124,7 @@ impl<T: Clone> Clone for Vec<T> { // self.len <= other.len due to the truncate above, so the // slice here is always in-bounds. - self.push_all(&other[len..]); + self.extend_from_slice(&other[len..]); } } @@ -1350,6 +1371,21 @@ impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> { } } +macro_rules! __impl_slice_eq1 { + ($Lhs: ty, $Rhs: ty) => { + __impl_slice_eq1! { $Lhs, $Rhs, Sized } + }; + ($Lhs: ty, $Rhs: ty, $Bound: ident) => { + #[stable(feature = "rust1", since = "1.0.0")] + impl<'a, 'b, A: $Bound, B> PartialEq<$Rhs> for $Lhs where A: PartialEq<B> { + #[inline] + fn eq(&self, other: &$Rhs) -> bool { self[..] == other[..] } + #[inline] + fn ne(&self, other: &$Rhs) -> bool { self[..] != other[..] } + } + } +} + __impl_slice_eq1! { Vec<A>, Vec<B> } __impl_slice_eq1! { Vec<A>, &'b [B] } __impl_slice_eq1! { Vec<A>, &'b mut [B] } @@ -1605,7 +1641,7 @@ impl<T> Drop for IntoIter<T> { } /// A draining iterator for `Vec<T>`. -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] pub struct Drain<'a, T: 'a> { /// Index of tail to preserve tail_start: usize, @@ -1616,9 +1652,9 @@ pub struct Drain<'a, T: 'a> { vec: *mut Vec<T>, } -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {} -#[unstable(feature = "drain", reason = "recently added", issue = "27711")] +#[stable(feature = "drain", since = "1.6.0")] unsafe impl<'a, T: Send> Send for Drain<'a, T> {} #[stable(feature = "rust1", since = "1.0.0")] |
