std-method
BTreeSet::pop_first
Remove and return the smallest member, if present. Duplicate priorities cannot be retained in a set unless the key includes a tie-breaker. Expected stdout (not executed): Some(4) [9, 12] Common mistake: Expecting the earliest inserted member.
Formal Syntax & Structure
rust syntaxrust
fn pop_first(&mut self) -> Option<T>Working Example
Example Snippetrust
fn main() { use std::collections::BTreeSet; let mut tickets = BTreeSet::from([12, 4, 9]); println!("{:?}", tickets.pop_first()); println!("{:?}", tickets.into_iter().collect::<Vec<_>>());}