std-method

BTreeMap::first_entry

Obtain a mutable handle to the smallest-key record. Update that value or remove the entry using its handle; no entry exists in an empty map. Expected stdout (not executed): 5 Common mistake: Trying to insert a new key through the occupied handle.

Formal Syntax & Structure

rust syntaxrust
fn first_entry(&mut self) -> Option<OccupiedEntry<'_, K, V>>

Working Example

Example Snippetrust
fn main() {    use std::collections::BTreeMap;    let mut jobs = BTreeMap::from([(9, 2), (3, 1)]);    if let Some(mut item) = jobs.first_entry() { *item.get_mut() += 4; }    println!("{}", jobs[&3]);}
Rust Reference