-
-
Save rust-play/32b4ac94f2476d930288a70477203cd3 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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