@@ -1442,28 +1442,37 @@ impl<T, A: Allocator> Vec<T, A> {
14421442
14431443    /// Converts the vector into [`Box<[T]>`][owned slice]. 
14441444/// 
1445- /// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`]. 
1445+ /// Before the conversion, this will attempt to shrink the vector's allocation to match its length, 
1446+ /// but the final memory layout depends on the allocator's [memory fitting][memory-fitting] strategy. 
1447+ /// The returned slice will have exactly [`len`] elements, but take note that the underlying allocation 
1448+ /// may still contain unused capacity that is safe to use with sized deallocation methods. 
14461449/// 
1450+ /// When converting back to a vector using `Box<[T]>::into_vec`, the resulting 
1451+ /// vector may retain this extra capacity. For details about allocator behavior, 
1452+ /// see [`Allocator::shrink`] and the [memory fitting] documentation. 
1453+ /// 
1454+ /// [`len`]: Vec::len 
14471455/// [owned slice]: Box 
1456+ /// [memory-fitting]: Allocator#memory-fitting 
14481457/// [`shrink_to_fit`]: Vec::shrink_to_fit 
14491458/// 
14501459/// # Examples 
14511460/// 
1461+ /// Basic conversion: 
14521462/// ``` 
14531463/// let v = vec![1, 2, 3]; 
1454- /// 
14551464/// let slice = v.into_boxed_slice(); 
14561465/// ``` 
14571466/// 
1458- /// Any excess capacity is removed: 
1459- /// 
1467+ /// Preserved allocation size when converting back: 
14601468/// ``` 
14611469/// let mut vec = Vec::with_capacity(10); 
14621470/// vec.extend([1, 2, 3]); 
14631471/// 
1464- /// assert!(vec.capacity() >= 10); 
14651472/// let slice = vec.into_boxed_slice(); 
1466- /// assert_eq!(slice.into_vec().capacity(), 3); 
1473+ /// let new_vec = slice.into_vec(); 
1474+ /// // The allocator may have kept extra capacity: 
1475+ /// assert!(new_vec.capacity() >= 3); 
14671476/// ``` 
14681477#[ cfg( not( no_global_oom_handling) ) ]  
14691478    #[ stable( feature = "rust1" ,  since = "1.0.0" ) ]  
0 commit comments