use std::collections::HashMap; fn main() { let mut scores = HashMap::new(); scores.insert("Alice", 85); scores.insert("Bob", 92); scores.insert("Carol", 78); scores.insert("Dave", 88); // Retain only scores of 80 or above scores.retain(|_name, &mut score| score >= 80); println!("{:?}", scores); // Output: {"Alice": 85, "Bob": 92, "Dave": 88} }
Write, Run & Share Rust code online using OneCompiler's Rust online compiler for free. It's one of the robust, feature-rich online compilers for Rust language. Getting started with the OneCompiler's Rust editor is easy and fast. The editor shows sample boilerplate code when you choose language as Rust and start coding.