std-method

BTreeMap::into_keys

Consume an ordered map and yield owned keys in key order. Associated values are discarded as the iterator is consumed or dropped. Expected stdout (not executed): [1, 4] Common mistake: Trying to access the map after consuming it.

Formal Syntax & Structure

rust syntaxrust
fn into_keys(self) -> IntoKeys<K, V>

Working Example

Example Snippetrust
fn main() {    use std::collections::BTreeMap;    let rooms = BTreeMap::from([(4, "blue"), (1, "red")]);    println!("{:?}", rooms.into_keys().collect::<Vec<_>>());}
Rust Reference