Created
January 9, 2018 04:28
-
-
Save anonymous/8fbaf3ad6990d116eed09b0f5591b421 to your computer and use it in GitHub Desktop.
Rust code shared from the 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::collections::hash_map::Entry; | |
fn main() { | |
let mut d = HashMap::new(); | |
match d.entry("k1") { | |
Entry::Vacant(e) => { | |
e.insert(Vec::new()); | |
} | |
Entry::Occupied(mut e) => { | |
e.get_mut().push("v1"); | |
} | |
} | |
match d.entry("k1") { | |
Entry::Vacant(e) => { | |
e.insert(Vec::new()); | |
} | |
Entry::Occupied(mut e) => { | |
e.get_mut().push("v1"); | |
} | |
} | |
println!("{:?}", d); | |
// {"k1": ["v1"]} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment