Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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"]}
- }
Add Comment
Please, Sign In to add comment