diff options
| author | bors <bors@rust-lang.org> | 2016-07-19 05:12:51 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-19 05:12:51 -0700 |
| commit | 27e766d7bc84be992c8ddef710affc92ef4a0adf (patch) | |
| tree | f345cf9cdd68dfc339f34e09b7dd3229d1c7c825 /src/libcollections | |
| parent | 92400cf8dcf411ce7e70ab2960639977d46d5b01 (diff) | |
| parent | 88b37b6d9cf8cbe12550c0ac5399e9cf08674ca9 (diff) | |
| download | rust-27e766d7bc84be992c8ddef710affc92ef4a0adf.tar.gz rust-27e766d7bc84be992c8ddef710affc92ef4a0adf.zip | |
Auto merge of #34898 - sanxiyn:rollup, r=sanxiyn
Rollup of 5 pull requests - Successful merges: #34807, #34853, #34875, #34884, #34889 - Failed merges:
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/string.rs | 6 | ||||
| -rw-r--r-- | src/libcollections/vec.rs | 37 |
2 files changed, 41 insertions, 2 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index eedf4c2c11f..8ba5c6ffbf2 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -701,6 +701,12 @@ impl String { /// Violating these may cause problems like corrupting the allocator's /// internal datastructures. /// + /// The ownership of `ptr` is effectively transferred to the + /// `String` which may then deallocate, reallocate or change the + /// contents of memory pointed to by the pointer at will. Ensure + /// that nothing else uses the pointer after calling this + /// function. + /// /// # Examples /// /// Basic usage: diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 7a3c9bc3bb2..518b94b5031 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -342,12 +342,18 @@ impl<T> Vec<T> { /// /// * `ptr` needs to have been previously allocated via `String`/`Vec<T>` /// (at least, it's highly likely to be incorrect if it wasn't). - /// * `length` needs to be the length that less than or equal to `capacity`. + /// * `length` needs to be less than or equal to `capacity`. /// * `capacity` needs to be the capacity that the pointer was allocated with. /// /// Violating these may cause problems like corrupting the allocator's /// internal datastructures. /// + /// The ownership of `ptr` is effectively transferred to the + /// `Vec<T>` which may then deallocate, reallocate or change the + /// contents of memory pointed to by the pointer at will. Ensure + /// that nothing else uses the pointer after calling this + /// function. + /// /// # Examples /// /// ``` @@ -479,18 +485,45 @@ impl<T> Vec<T> { } } - /// Shorten a vector to be `len` elements long, dropping excess elements. + /// Shortens the vector, keeping the first `len` elements and dropping + /// the rest. /// /// If `len` is greater than the vector's current length, this has no /// effect. /// + /// The [`drain`] method can emulate `truncate`, but causes the excess + /// elements to be returned instead of dropped. + /// /// # Examples /// + /// Truncating a five element vector to two elements: + /// /// ``` /// let mut vec = vec![1, 2, 3, 4, 5]; /// vec.truncate(2); /// assert_eq!(vec, [1, 2]); /// ``` + /// + /// No truncation occurs when `len` is greater than the vector's current + /// length: + /// + /// ``` + /// let mut vec = vec![1, 2, 3]; + /// vec.truncate(8); + /// assert_eq!(vec, [1, 2, 3]); + /// ``` + /// + /// Truncating when `len == 0` is equivalent to calling the [`clear`] + /// method. + /// + /// ``` + /// let mut vec = vec![1, 2, 3]; + /// vec.truncate(0); + /// assert_eq!(vec, []); + /// ``` + /// + /// [`clear`]: #method.clear + /// [`drain`]: #method.drain #[stable(feature = "rust1", since = "1.0.0")] pub fn truncate(&mut self, len: usize) { unsafe { |
