Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created December 5, 2022 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/32b4ac94f2476d930288a70477203cd3 to your computer and use it in GitHub Desktop.
Save rust-play/32b4ac94f2476d930288a70477203cd3 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
use std::collections::HashMap;
use std::vec::Vec;
fn main() -> ()
{
let mut map : HashMap<String, String> = HashMap::new();
map.insert("Bob".into(), "Marley".into());
map.insert("Jack".into(), "Ryan".into());
map.insert("Bill".into(), "Tilden".into());
let mut keys : Vec<&str> = Vec::new();
{
let ks = map.keys();
for key in ks
{
keys.push(key);
}
}
let mut iter = keys.iter();
loop
{
match iter.next() {
Some(key) => {
let key : String = (*key).into();
map.remove(&key);
}
None => break
}
}
println!("len {}", map.len());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment