Auto merge of #30272 - tshepang:doc-drain, r=bluss
Second sentence actually repeats info from first sentence. "from start to end" also feels like it adds nothing. I also extended Vec::drain example.
This commit is contained in:
commit
f963eb2870
@ -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
|
||||
///
|
||||
|
@ -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
|
||||
@ -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>
|
||||
|
@ -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).
|
||||
///
|
||||
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user