Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::HashMap;
- fn main() {
- let mut hm = HashMap::new();
- hm.insert(1, "test");
- // This does not work
- if let Some(first) = hm.get_mut(&1) {
- // do things
- } else {
- match some_enum {
- SomeEnum::Foo(x) => { hm.insert(1, value); }
- SomeEnum::Bar(x) => { }
- }
- }
- // this works but is a bit ugly
- /*
- let need_insert = {
- if let Some(first) = hm.get_mut(&1) {
- false
- } else { true }
- };
- if need_insert {
- hm.insert(1, "test");
- }
- */
- }
Add Comment
Please, Sign In to add comment