-
-
Save whatalnk/8a11c7dc82e77de962e4052df760c95e 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
https://play.rust-lang.org/?gist=8fbaf3ad6990d116eed09b0f5591b421&version=stable