Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f1b48b9

Browse files
committedFeb 8, 2022
Improve the documentation of drain members
1 parent 2a8dbdb commit f1b48b9

File tree

5 files changed

+21
-24
lines changed

5 files changed

+21
-24
lines changed
 

‎library/alloc/src/collections/binary_heap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ impl<T: Ord> BinaryHeap<T> {
748748

749749
/// Returns an iterator which retrieves elements in heap order.
750750
/// The retrieved elements are removed from the original heap.
751-
/// The remaining elements will be removed on drop in heap order.
751+
/// On drop, the remaining elements are removed and dropped in heap order.
752752
///
753753
/// Note:
754754
/// * `.drain_sorted()` is *O*(*n* \* log(*n*)); much slower than `.drain()`.

‎library/alloc/src/collections/vec_deque/mod.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,15 +1215,14 @@ impl<T, A: Allocator> VecDeque<T, A> {
12151215
unsafe { IterMut::new(ring, tail, head, PhantomData) }
12161216
}
12171217

1218-
/// Creates a draining iterator that removes the specified range in the
1219-
/// `VecDeque` and yields the removed items.
1218+
/// Removes the specified range from the `VecDeque`, returning all removed
1219+
/// elements as an iterator.
12201220
///
1221-
/// Note 1: The element range is removed even if the iterator is not
1222-
/// consumed until the end.
1223-
///
1224-
/// Note 2: It is unspecified how many elements are removed from the deque,
1225-
/// if the `Drain` value is not dropped, but the borrow it holds expires
1226-
/// (e.g., due to `mem::forget`).
1221+
/// When the iterator **is** dropped, it drops any elements that it has not
1222+
/// yet yielded (none if the iterator was fully consumed).
1223+
/// If the iterator **is not** dropped (with [`mem::forget`], for example),
1224+
/// it is unspecified which elements remain in the vector; even elements
1225+
/// outside the range may have been removed and leaked.
12271226
///
12281227
/// # Panics
12291228
///
@@ -1240,7 +1239,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
12401239
/// assert_eq!(drained, [3]);
12411240
/// assert_eq!(v, [1, 2]);
12421241
///
1243-
/// // A full range clears all contents
1242+
/// // A full range clears all contents, like `clear()` does
12441243
/// v.drain(..);
12451244
/// assert!(v.is_empty());
12461245
/// ```

‎library/alloc/src/string.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,11 +1628,8 @@ impl String {
16281628
self.vec.clear()
16291629
}
16301630

1631-
/// Creates a draining iterator that removes the specified range in the `String`
1632-
/// and yields the removed `chars`.
1633-
///
1634-
/// Note: The element range is removed even if the iterator is not
1635-
/// consumed until the end.
1631+
/// Removes the specified range from the string, returning all removed
1632+
/// characters as an iterator.
16361633
///
16371634
/// # Panics
16381635
///
@@ -1652,7 +1649,7 @@ impl String {
16521649
/// assert_eq!(t, "α is alpha, ");
16531650
/// assert_eq!(s, "β is beta");
16541651
///
1655-
/// // A full range clears the string
1652+
/// // A full range clears the string, like `clear()` does
16561653
/// s.drain(..);
16571654
/// assert_eq!(s, "");
16581655
/// ```

‎library/alloc/src/vec/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,13 +1799,14 @@ impl<T, A: Allocator> Vec<T, A> {
17991799
self.len += count;
18001800
}
18011801

1802-
/// Creates a draining iterator that removes the specified range in the vector
1803-
/// and yields the removed items.
1802+
/// Removes the specified range from the vector, returning all removed
1803+
/// elements as an iterator.
18041804
///
1805-
/// When the iterator **is** dropped, all elements in the range are removed
1806-
/// from the vector, even if the iterator was not fully consumed. If the
1807-
/// iterator **is not** dropped (with [`mem::forget`] for example), it is
1808-
/// unspecified how many elements are removed.
1805+
/// When the iterator **is** dropped, it drops any elements that it has not
1806+
/// yet yielded (none if the iterator was fully consumed).
1807+
/// If the iterator **is not** dropped (with [`mem::forget`], for example),
1808+
/// it is unspecified which elements remain in the vector; even elements
1809+
/// outside the range may have been removed and leaked.
18091810
///
18101811
/// # Panics
18111812
///
@@ -1820,7 +1821,7 @@ impl<T, A: Allocator> Vec<T, A> {
18201821
/// assert_eq!(v, &[1]);
18211822
/// assert_eq!(u, &[2, 3]);
18221823
///
1823-
/// // A full range clears the vector
1824+
/// // A full range clears the vector, like `clear()` does
18241825
/// v.drain(..);
18251826
/// assert_eq!(v, &[]);
18261827
/// ```

‎library/std/src/collections/hash/set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<T, S> HashSet<T, S> {
227227
self.base.is_empty()
228228
}
229229

230-
/// Clears the set, returning all elements in an iterator.
230+
/// Clears the set, returning all elements as an iterator.
231231
///
232232
/// # Examples
233233
///

0 commit comments

Comments
 (0)
Please sign in to comment.