std-method

VecDeque::front

Borrow the first element without removing it. Empty queues return None. Use front_mut for a mutable borrow and pop_front for ownership. Expected stdout (not executed): Some(12) 2 Common mistake: Assuming inspection consumes the item.

Formal Syntax & Structure

rust syntaxrust
pub fn front(&self) -> Option<&T>

Working Example

Example Snippetrust
fn main() {    use std::collections::VecDeque;    let q = VecDeque::from([12, 24]);    println!("{:?} {}", q.front(), q.len());}
Rust Reference