std-type
btree_map::Entry — occupied or vacant
A handle represents the two possible states of one key. Match its variants when the two cases need different actions. Expected stdout (not executed): 1 Common mistake: Treating Entry as a standalone owned record.
Formal Syntax & Structure
rust syntaxrust
Entry<'a, K, V>Working Example
Example Snippetrust
fn main() { use std::collections::BTreeMap; use std::collections::btree_map::Entry; let mut rooms = BTreeMap::from([(1, 2)]); match rooms.entry(3) { Entry::Occupied(mut e) => { *e.get_mut() += 1; } Entry::Vacant(e) => { e.insert(1); } } println!("{}", rooms[&3]);}