красиво через get_mut ?
                  
                  
                  
                  
                  
                  if let Some(x) = my_hashmap.get_mut(&key) {
                  
                  
                    *x = *x+1;
                  
                  
                  } else {
                  
                  
                    my_hashmap.insert(key, 1);
                  
                  
                  }
                  
                  
                  
                  
                  
                  приводит к:
                  
                  
                  
                  
                  
                  11 |     if let Some(x) = my_hashmap.get_mut(&key) {
                  
                  
                     |                      ---------- first mutable borrow occurs here
                  
                  
                  ...
                  
                  
                  14 |         my_hashmap.insert(key, 1);
                  
                  
                     |         ^^^^^^^^^^ second mutable borrow occurs here
                  
                  
                  15 |     }
                  
                  
                     |     - first borrow ends here
                  
                  
                
изначально вижу что X это не мутирующий!!
Обсуждают сегодня