Vec::with_capacity
pub static fn with_capacity(int n) -> Vec<T>
Source: compiler/src/builtin_docs/prelude.hy Creates an empty vector with room for at least n elements.
Pushing up to n elements does not reallocate. The length is still 0.
Parameters#
| Name | Type |
|---|---|
n | int |
Returns#
Vec<T>
Examples#
use tests::assert;
let v: Vec<int> = Vec::with_capacity(16);
assert!(v.len() == 0);
assert!(v.capacity() >= 16);
See also#
Vec: A growable, heap-allocated vector ofTvalues.Vec::new: Creates a new, empty vector.Vec::from: Creates a vector holding a copy of the elements of the fixed arrayarr.Vec::push: Appendsxto the end of the vector.Vec::pop: Removes the last element and returns it, orNonewhen the vector is empty.Vec::insert: Insertsxat indexi, shifting later elements one place to the right.Vec::remove: Removes the element at indexiand returns it, shifting later elements left.Vec::clear: Removes every element.