Guest User

Untitled

a guest
May 20th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. use std::collections::HashMap;
  2.  
  3. fn main() {
  4. let mut hm = HashMap::new();
  5. hm.insert(1, "test");
  6.  
  7. // This does not work
  8. if let Some(first) = hm.get_mut(&1) {
  9. // do things
  10. } else {
  11. hm.insert(1, "test");
  12. }
  13.  
  14. // this works but is a bit ugly
  15. /*
  16. let need_insert = {
  17. if let Some(first) = hm.get_mut(&1) {
  18. false
  19. } else { true }
  20. };
  21.  
  22. if need_insert {
  23. hm.insert(1, "test");
  24. }
  25. */
  26. }
Add Comment
Please, Sign In to add comment