@@ -1442,28 +1442,34 @@ impl<T, A: Allocator> Vec<T, A> {
1442
1442
1443
1443
/// Converts the vector into [`Box<[T]>`][owned slice].
1444
1444
///
1445
- /// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
1445
+ /// This method may shrink the vector to fit, similar to [`shrink_to_fit`], and the exact
1446
+ /// behavior also depends on the allocator implementation. The returned slice will have a length
1447
+ /// matching the element count, but the allocator may preserve additional capacity according to
1448
+ /// its memory layout requirements.
1449
+ ///
1450
+ /// For details about how allocators handle memory fitting and when shrinking occurs, see
1451
+ /// [the "Memory Fitting" section in `Allocator`][memory-fitting] and [`Allocator::shrink`].
1446
1452
///
1447
1453
/// [owned slice]: Box
1448
1454
/// [`shrink_to_fit`]: Vec::shrink_to_fit
1455
+ /// [memory-fitting]: Allocator#memory-fitting
1449
1456
///
1450
1457
/// # Examples
1451
1458
///
1452
1459
/// ```
1453
1460
/// let v = vec![1, 2, 3];
1454
- ///
1455
1461
/// let slice = v.into_boxed_slice();
1456
1462
/// ```
1457
1463
///
1458
- /// Any excess capacity is removed :
1464
+ /// Excess capacity may be preserved :
1459
1465
///
1460
1466
/// ```
1461
1467
/// let mut vec = Vec::with_capacity(10);
1462
1468
/// vec.extend([1, 2, 3]);
1463
1469
///
1464
1470
/// assert!(vec.capacity() >= 10);
1465
1471
/// let slice = vec.into_boxed_slice();
1466
- /// assert_eq !(slice.into_vec().capacity(), 3);
1472
+ /// assert !(slice.into_vec().capacity() >= 3);
1467
1473
/// ```
1468
1474
#[ cfg( not( no_global_oom_handling) ) ]
1469
1475
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
0 commit comments