Guest User

Untitled

a guest
Jan 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. use std::collections::HashMap;
  2. use std::collections::hash_map::Entry;
  3.  
  4. fn main() {
  5. let mut d = HashMap::new();
  6. match d.entry("k1") {
  7. Entry::Vacant(e) => {
  8. e.insert(Vec::new());
  9. }
  10. Entry::Occupied(mut e) => {
  11. e.get_mut().push("v1");
  12. }
  13. }
  14. match d.entry("k1") {
  15. Entry::Vacant(e) => {
  16. e.insert(Vec::new());
  17. }
  18. Entry::Occupied(mut e) => {
  19. e.get_mut().push("v1");
  20. }
  21. }
  22. println!("{:?}", d);
  23. // {"k1": ["v1"]}
  24. }
Add Comment
Please, Sign In to add comment