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/string.rs | |
| parent | feac2ecf1cae1dd0f56bed1cecc6e109c64b3d4f (diff) | |
| download | rust-a677e6084049ff4cb2e338d7e33dc034846cdb29.tar.gz rust-a677e6084049ff4cb2e338d7e33dc034846cdb29.zip | |
Collections: improve the documentation of drain members
Diffstat (limited to 'library/alloc/src/string.rs')
| -rw-r--r-- | library/alloc/src/string.rs | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index 7c0faf0659a..716bb4983a6 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -1628,17 +1628,24 @@ impl String { self.vec.clear() } - /// Creates a draining iterator that removes the specified range in the `String` - /// and yields the removed `chars`. + /// Removes the specified range from the string in bulk, returning all + /// removed characters as an iterator. /// - /// Note: The element range is removed even if the iterator is not - /// consumed until the end. + /// The returned iterator keeps a mutable borrow on the string to optimize + /// its implementation. /// /// # Panics /// /// Panics if the starting point or end point do not lie on a [`char`] /// boundary, or if they're out of bounds. /// + /// # Leaking + /// + /// If the returned iterator goes out of scope without being dropped (due to + /// [`core::mem::forget`], for example), the string may still contain a copy + /// of any drained characters, or may have lost characters arbitrarily, + /// including characters outside the range. + /// /// # Examples /// /// Basic usage: @@ -1652,7 +1659,7 @@ impl String { /// assert_eq!(t, "α is alpha, "); /// assert_eq!(s, "β is beta"); /// - /// // A full range clears the string + /// // A full range clears the string, like `clear()` does /// s.drain(..); /// assert_eq!(s, ""); /// ``` |
