Skip to content

Commit 72ed17b

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#35181 - GuillaumeGomez:vec_doc, r=steveklabnik
Add doc example for Vec Fixes rust-lang#29380. r? @steveklabnik
2 parents d6caa64 + 1fa9b8d commit 72ed17b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/libcollections/vec.rs

+19
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,25 @@ impl<T> Vec<T> {
476476
/// Note that this will drop any excess capacity. Calling this and
477477
/// converting back to a vector with `into_vec()` is equivalent to calling
478478
/// `shrink_to_fit()`.
479+
///
480+
/// # Examples
481+
///
482+
/// ```
483+
/// let v = vec![1, 2, 3];
484+
///
485+
/// let slice = v.into_boxed_slice();
486+
/// ```
487+
///
488+
/// Any excess capacity is removed:
489+
///
490+
/// ```
491+
/// let mut vec = Vec::with_capacity(10);
492+
/// vec.extend([1, 2, 3].iter().cloned());
493+
///
494+
/// assert_eq!(vec.capacity(), 10);
495+
/// let slice = vec.into_boxed_slice();
496+
/// assert_eq!(slice.into_vec().capacity(), 3);
497+
/// ```
479498
#[stable(feature = "rust1", since = "1.0.0")]
480499
pub fn into_boxed_slice(mut self) -> Box<[T]> {
481500
unsafe {

0 commit comments

Comments
 (0)