Vec::insert
pub fn insert(int i, T x)
Source: compiler/src/builtin_docs/prelude.hy Inserts x at index i, shifting later elements one place to the right.
i may equal len() (append).
Called on a Vec value as value.insert(…).
Parameters#
| Name | Type |
|---|---|
i | int |
x | T |
Panics#
Panics when i is negative or greater than len().
Examples#
use tests::assert;
let v: Vec<int> = [1, 3];
v.insert(1, 2);
v.insert(3, 4);
assert!(v[1] == 2);
assert!(v[3] == 4);
See also#
Vec::lenVec: A growable, heap-allocated vector ofTvalues.Vec::new: Creates a new, empty vector.Vec::with_capacity: Creates an empty vector with room for at leastnelements.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::remove: Removes the element at indexiand returns it, shifting later elements left.