Vec::remove
pub fn remove(int i) -> Option<T>
Source: compiler/src/builtin_docs/prelude.hy Removes the element at index i and returns it, shifting later elements left.
Returns None (and leaves the vector unchanged) when i is out of range.
Called on a Vec value as value.remove(…).
Parameters#
| Name | Type |
|---|---|
i | int |
Returns#
Option<T>
Examples#
use tests::assert;
let v: Vec<int> = [10, 20, 30];
assert!((v.remove(0) ?? 0) == 10);
assert!(v[0] == 20);
assert!((v.remove(9) ?? -1) == -1);
See also#
Vec: 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::insert: Insertsxat indexi, shifting later elements one place to the right.Vec::clear: Removes every element.