Skip to content

Commit

Permalink
Auto merge of #30272 - tshepang:doc-drain, r=bluss
Browse files Browse the repository at this point in the history
Second sentence actually repeats info from first sentence. "from start to end" also feels like it adds nothing.

I also extended Vec::drain example.
  • Loading branch information
bors committed Dec 18, 2015
2 parents 27d5511 + 46e2296 commit f963eb2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,8 +1201,10 @@ impl String {
}

/// Create a draining iterator that removes the specified range in the string
/// and yields the removed chars from start to end. The element range is
/// removed even if the iterator is not consumed until the end.
/// and yields the removed chars.
///
/// Note: The element range is removed even if the iterator is not
/// consumed until the end.
///
/// # Panics
///
Expand Down
17 changes: 11 additions & 6 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,10 +725,12 @@ impl<T> Vec<T> {
}

/// Create a draining iterator that removes the specified range in the vector
/// and yields the removed items from start to end. The element range is
/// removed even if the iterator is not consumed until the end.
/// and yields the removed items.
///
/// Note: It is unspecified how many elements are removed from the vector,
/// Note 1: The element range is removed even if the iterator is not
/// consumed until the end.
///
/// Note 2: It is unspecified how many elements are removed from the vector,
/// if the `Drain` value is leaked.
///
/// # Panics
Expand All @@ -739,11 +741,14 @@ impl<T> Vec<T> {
/// # Examples
///
/// ```
/// // Draining using `..` clears the whole vector.
/// let mut v = vec![1, 2, 3];
/// let u: Vec<_> = v.drain(..).collect();
/// let u: Vec<_> = v.drain(1..).collect();
/// assert_eq!(v, &[1]);
/// assert_eq!(u, &[2, 3]);
///
/// // A full range clears the vector
/// v.drain(..);
/// assert_eq!(v, &[]);
/// assert_eq!(u, &[1, 2, 3]);
/// ```
#[stable(feature = "drain", since = "1.6.0")]
pub fn drain<R>(&mut self, range: R) -> Drain<T>
Expand Down
18 changes: 11 additions & 7 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,12 @@ impl<T> VecDeque<T> {
}

/// Create a draining iterator that removes the specified range in the
/// `VecDeque` and yields the removed items from start to end. The element
/// range is removed even if the iterator is not consumed until the end.
/// `VecDeque` and yields the removed items.
///
/// Note: It is unspecified how many elements are removed from the deque,
/// Note 1: The element range is removed even if the iterator is not
/// consumed until the end.
///
/// Note 2: It is unspecified how many elements are removed from the deque,
/// if the `Drain` value is not dropped, but the borrow it holds expires
/// (eg. due to mem::forget).
///
Expand All @@ -779,11 +781,13 @@ impl<T> VecDeque<T> {
///
/// ```
/// use std::collections::VecDeque;
/// let mut v: VecDeque<_> = vec![1, 2, 3].into_iter().collect();
/// assert_eq!(vec![3].into_iter().collect::<VecDeque<_>>(), v.drain(2..).collect());
/// assert_eq!(vec![1, 2].into_iter().collect::<VecDeque<_>>(), v);
///
/// // draining using `..` clears the whole deque.
/// let mut v = VecDeque::new();
/// v.push_back(1);
/// assert_eq!(v.drain(..).next(), Some(1));
/// // A full range clears all contents
/// v.drain(..);
/// assert!(v.is_empty());
/// ```
#[inline]
Expand Down

0 comments on commit f963eb2

Please sign in to comment.