Skip to content

Commit 8f8cd2c

Browse files
committed
update doc for Vec::into_boxed_slice
1 parent bb029a1 commit 8f8cd2c

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

library/alloc/src/vec/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1442,28 +1442,34 @@ 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+
/// 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`].
14461452
///
14471453
/// [owned slice]: Box
14481454
/// [`shrink_to_fit`]: Vec::shrink_to_fit
1455+
/// [memory-fitting]: Allocator#memory-fitting
14491456
///
14501457
/// # Examples
14511458
///
14521459
/// ```
14531460
/// let v = vec![1, 2, 3];
1454-
///
14551461
/// let slice = v.into_boxed_slice();
14561462
/// ```
14571463
///
1458-
/// Any excess capacity is removed:
1464+
/// Excess capacity may be preserved:
14591465
///
14601466
/// ```
14611467
/// let mut vec = Vec::with_capacity(10);
14621468
/// vec.extend([1, 2, 3]);
14631469
///
14641470
/// assert!(vec.capacity() >= 10);
14651471
/// let slice = vec.into_boxed_slice();
1466-
/// assert_eq!(slice.into_vec().capacity(), 3);
1472+
/// assert!(slice.into_vec().capacity() >= 3);
14671473
/// ```
14681474
#[cfg(not(no_global_oom_handling))]
14691475
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)