Skip to content

Commit 5eda958

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#103326
2 parents bcc42ba + 674cd61 commit 5eda958

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

library/alloc/src/vec/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -868,13 +868,14 @@ impl<T, A: Allocator> Vec<T, A> {
868868
(ptr, len, capacity, alloc)
869869
}
870870

871-
/// Returns the number of elements the vector can hold without
871+
/// Returns the total number of elements the vector can hold without
872872
/// reallocating.
873873
///
874874
/// # Examples
875875
///
876876
/// ```
877-
/// let vec: Vec<i32> = Vec::with_capacity(10);
877+
/// let mut vec: Vec<i32> = Vec::with_capacity(10);
878+
/// vec.push(42);
878879
/// assert_eq!(vec.capacity(), 10);
879880
/// ```
880881
#[inline]

0 commit comments

Comments
 (0)