Rollup merge of #120110 - invpt:patch-1, r=the8472
Update documentation for Vec::into_boxed_slice to be more clear about excess capacity Currently, the documentation for Vec::into_boxed_slice says that "if the vector has excess capacity, its items will be moved into a newly-allocated buffer with exactly the right capacity." This is misleading, as copies do not necessarily occur, depending on if the allocator supports in-place shrinking. I copied some of the wording from shrink_to_fit, though it could potentially still be worded better than this.
This commit is contained in:
commit
7219bd22ed
@ -358,7 +358,7 @@
|
|||||||
///
|
///
|
||||||
/// `vec![x; n]`, `vec![a, b, c, d]`, and
|
/// `vec![x; n]`, `vec![a, b, c, d]`, and
|
||||||
/// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec`
|
/// [`Vec::with_capacity(n)`][`Vec::with_capacity`], will all produce a `Vec`
|
||||||
/// with exactly the requested capacity. If <code>[len] == [capacity]</code>,
|
/// with at least the requested capacity. If <code>[len] == [capacity]</code>,
|
||||||
/// (as is the case for the [`vec!`] macro), then a `Vec<T>` can be converted to
|
/// (as is the case for the [`vec!`] macro), then a `Vec<T>` can be converted to
|
||||||
/// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
|
/// and from a [`Box<[T]>`][owned slice] without reallocating or moving the elements.
|
||||||
///
|
///
|
||||||
@ -1023,8 +1023,11 @@ pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveE
|
|||||||
|
|
||||||
/// Shrinks the capacity of the vector as much as possible.
|
/// Shrinks the capacity of the vector as much as possible.
|
||||||
///
|
///
|
||||||
/// It will drop down as close as possible to the length but the allocator
|
/// The behavior of this method depends on the allocator, which may either shrink the vector
|
||||||
/// may still inform the vector that there is space for a few more elements.
|
/// in-place or reallocate. The resulting vector might still have some excess capacity, just as
|
||||||
|
/// is the case for [`with_capacity`]. See [`Allocator::shrink`] for more details.
|
||||||
|
///
|
||||||
|
/// [`with_capacity`]: Vec::with_capacity
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
@ -1074,10 +1077,10 @@ pub fn shrink_to(&mut self, min_capacity: usize) {
|
|||||||
|
|
||||||
/// Converts the vector into [`Box<[T]>`][owned slice].
|
/// Converts the vector into [`Box<[T]>`][owned slice].
|
||||||
///
|
///
|
||||||
/// If the vector has excess capacity, its items will be moved into a
|
/// Before doing the conversion, this method discards excess capacity like [`shrink_to_fit`].
|
||||||
/// newly-allocated buffer with exactly the right capacity.
|
|
||||||
///
|
///
|
||||||
/// [owned slice]: Box
|
/// [owned slice]: Box
|
||||||
|
/// [`shrink_to_fit`]: Vec::shrink_to_fit
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
@ -3290,8 +3293,10 @@ fn from(s: Box<[T], A>) -> Self {
|
|||||||
impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> {
|
impl<T, A: Allocator> From<Vec<T, A>> for Box<[T], A> {
|
||||||
/// Convert a vector into a boxed slice.
|
/// Convert a vector into a boxed slice.
|
||||||
///
|
///
|
||||||
/// If `v` has excess capacity, its items will be moved into a
|
/// Before doing the conversion, this method discards excess capacity like [`Vec::shrink_to_fit`].
|
||||||
/// newly-allocated buffer with exactly the right capacity.
|
///
|
||||||
|
/// [owned slice]: Box
|
||||||
|
/// [`Vec::shrink_to_fit`]: Vec::shrink_to_fit
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user