std-method
BTreeMap::append
Move records out of a second map into the first. On equal keys the value from the second map wins. The second map becomes empty. Expected stdout (not executed): new true Common mistake: Expecting the second map to retain its data.
Formal Syntax & Structure
rust syntaxrust
fn append(&mut self, other: &mut BTreeMap<K, V>)Working Example
Example Snippetrust
fn main() { use std::collections::BTreeMap; let mut main = BTreeMap::from([(1, "old"), (2, "keep")]); let mut patch = BTreeMap::from([(1, "new"), (3, "add")]); main.append(&mut patch); println!("{} {}", main[&1], patch.is_empty());}