diff options
| author | Stein Somers <git@steinsomers.be> | 2022-01-14 20:28:04 +0100 |
|---|---|---|
| committer | Stein Somers <git@steinsomers.be> | 2022-02-19 00:55:31 +0100 |
| commit | a677e6084049ff4cb2e338d7e33dc034846cdb29 (patch) | |
| tree | f211dc507059180d426f024719e9577a2e753ec7 /library/alloc/src/vec | |
| parent | feac2ecf1cae1dd0f56bed1cecc6e109c64b3d4f (diff) | |
| download | rust-a677e6084049ff4cb2e338d7e33dc034846cdb29.tar.gz rust-a677e6084049ff4cb2e338d7e33dc034846cdb29.zip | |
Collections: improve the documentation of drain members
Diffstat (limited to 'library/alloc/src/vec')
| -rw-r--r-- | library/alloc/src/vec/mod.rs | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 3dc3eee4133..c29aa0fec5b 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -1799,19 +1799,24 @@ impl<T, A: Allocator> Vec<T, A> { self.len += count; } - /// Creates a draining iterator that removes the specified range in the vector - /// and yields the removed items. + /// Removes the specified range from the vector in bulk, returning all + /// removed elements as an iterator. If the iterator is dropped before + /// being fully consumed, it drops the remaining removed elements. /// - /// When the iterator **is** dropped, all elements in the range are removed - /// from the vector, even if the iterator was not fully consumed. If the - /// iterator **is not** dropped (with [`mem::forget`] for example), it is - /// unspecified how many elements are removed. + /// The returned iterator keeps a mutable borrow on the vector to optimize + /// its implementation. /// /// # Panics /// /// Panics if the starting point is greater than the end point or if /// the end point is greater than the length of the vector. /// + /// # Leaking + /// + /// If the returned iterator goes out of scope without being dropped (due to + /// [`mem::forget`], for example), the vector may have lost and leaked + /// elements arbitrarily, including elements outside the range. + /// /// # Examples /// /// ``` @@ -1820,7 +1825,7 @@ impl<T, A: Allocator> Vec<T, A> { /// assert_eq!(v, &[1]); /// assert_eq!(u, &[2, 3]); /// - /// // A full range clears the vector + /// // A full range clears the vector, like `clear()` does /// v.drain(..); /// assert_eq!(v, &[]); /// ``` |
