Rollup merge of #103482 - aDotInTheVoid:vec-cap-docs, r=thomcc

Clairify Vec::capacity docs

Update both the text and example to be clear that the method gives *total*, (not *spare*) capacity

Fixes #103326
This commit is contained in:
Dylan DPC 2022-10-25 14:43:15 +05:30 committed by GitHub
commit 35b46de61b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -868,13 +868,14 @@ impl<T, A: Allocator> Vec<T, A> {
(ptr, len, capacity, alloc) (ptr, len, capacity, alloc)
} }
/// Returns the number of elements the vector can hold without /// Returns the total number of elements the vector can hold without
/// reallocating. /// reallocating.
/// ///
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// let vec: Vec<i32> = Vec::with_capacity(10); /// let mut vec: Vec<i32> = Vec::with_capacity(10);
/// vec.push(42);
/// assert_eq!(vec.capacity(), 10); /// assert_eq!(vec.capacity(), 10);
/// ``` /// ```
#[inline] #[inline]