@@ -725,10 +725,12 @@ impl<T> Vec<T> {
725
725
}
726
726
727
727
/// Create a draining iterator that removes the specified range in the vector
728
- /// and yields the removed items from start to end. The element range is
729
- /// removed even if the iterator is not consumed until the end.
728
+ /// and yields the removed items.
730
729
///
731
- /// Note: It is unspecified how many elements are removed from the vector,
730
+ /// Note 1: The element range is removed even if the iterator is not
731
+ /// consumed until the end.
732
+ ///
733
+ /// Note 2: It is unspecified how many elements are removed from the vector,
732
734
/// if the `Drain` value is leaked.
733
735
///
734
736
/// # Panics
@@ -739,11 +741,14 @@ impl<T> Vec<T> {
739
741
/// # Examples
740
742
///
741
743
/// ```
742
- /// // Draining using `..` clears the whole vector.
743
744
/// let mut v = vec![1, 2, 3];
744
- /// let u: Vec<_> = v.drain(..).collect();
745
+ /// let u: Vec<_> = v.drain(1..).collect();
746
+ /// assert_eq!(v, &[1]);
747
+ /// assert_eq!(u, &[2, 3]);
748
+ ///
749
+ /// // A full range clears the vector
750
+ /// v.drain(..);
745
751
/// assert_eq!(v, &[]);
746
- /// assert_eq!(u, &[1, 2, 3]);
747
752
/// ```
748
753
#[ stable( feature = "drain" , since = "1.6.0" ) ]
749
754
pub fn drain < R > ( & mut self , range : R ) -> Drain < T >
0 commit comments