File tree 1 file changed +19
-0
lines changed
1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -476,6 +476,25 @@ impl<T> Vec<T> {
476
476
/// Note that this will drop any excess capacity. Calling this and
477
477
/// converting back to a vector with `into_vec()` is equivalent to calling
478
478
/// `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
+ /// ```
479
498
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
480
499
pub fn into_boxed_slice ( mut self ) -> Box < [ T ] > {
481
500
unsafe {
You can’t perform that action at this time.
0 commit comments