std-method

VecDeque::pop_front

Remove and return the oldest item in a queue using push_back for insertion. Return None when empty. No suffix shift is needed for this end operation. Expected stdout (not executed): Some(10) Some(20) None Common mistake: Using indexing to remove a value, or treating None as a failure in normal queue exhaustion.

Formal Syntax & Structure

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

Working Example

Example Snippetrust
fn main() {    use std::collections::VecDeque;    let mut q = VecDeque::from([10, 20]);    println!("{:?} {:?} {:?}", q.pop_front(), q.pop_front(), q.pop_front());}
Rust Reference