vec.first()
RS-W1116The Vec
type provides the first()
and first_mut()
methods to retrieve
the first element of the vector. Similarly, the VecDeque
type provides the
front()
and front_mut()
methods.
Prefer using these instead of get(0)
and get_mut(0)
.
fn foo() {
let v = vec![1, 2, 3, 4];
let v_first = v.get(0);
let dq = VecDeque::from([1, 2, 3, 4]);
let dq_first_mut = dq.get_mut(0);
}
fn foo() {
let v = vec![1, 2, 3, 4];
let v_first = v.first();
let dq = VecDeque::from([1, 2, 3, 4]);
let dq_first_mut = dq.front_mut();
}