diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2016-08-05 16:12:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-08-05 16:12:54 +0200 |
| commit | 3ca18f725a5ffccf5392094c72986ba03389ffae (patch) | |
| tree | 85972b4728acebfb71642cf736add2da585c6028 /src | |
| parent | e377049262313dea8a286c93cd71630796ade0de (diff) | |
| parent | 1fa9b8dc96f95ec5d6c95746d58e96f507ab85fd (diff) | |
| download | rust-3ca18f725a5ffccf5392094c72986ba03389ffae.tar.gz rust-3ca18f725a5ffccf5392094c72986ba03389ffae.zip | |
Rollup merge of #35181 - GuillaumeGomez:vec_doc, r=steveklabnik
Add doc example for Vec Fixes #29380. r? @steveklabnik
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/vec.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 275f38b2f78..8b4fce158de 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -476,6 +476,25 @@ impl<T> Vec<T> { /// Note that this will drop any excess capacity. Calling this and /// converting back to a vector with `into_vec()` is equivalent to calling /// `shrink_to_fit()`. + /// + /// # Examples + /// + /// ``` + /// let v = vec![1, 2, 3]; + /// + /// let slice = v.into_boxed_slice(); + /// ``` + /// + /// Any excess capacity is removed: + /// + /// ``` + /// let mut vec = Vec::with_capacity(10); + /// vec.extend([1, 2, 3].iter().cloned()); + /// + /// assert_eq!(vec.capacity(), 10); + /// let slice = vec.into_boxed_slice(); + /// assert_eq!(slice.into_vec().capacity(), 3); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn into_boxed_slice(mut self) -> Box<[T]> { unsafe { |
