std-method

Vec::pop

Remove and return the final element as an owned value. Return None if empty; no index is required. This is useful for stack-like processing. Expected stdout (not executed): Some("edit") Some("open") None Common mistake: Calling unwrap without handling an empty stack.

Formal Syntax & Structure

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

Working Example

Example Snippetrust
fn main() {    let mut undo = vec!["open", "edit"];    println!("{:?} {:?} {:?}", undo.pop(), undo.pop(), undo.pop());}
Rust Reference