SHARE
TWEET

Untitled

a guest Apr 20th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::collections::HashMap;
  2.  
  3. const ORIGIN: [i32; 3] = [0, 0, 0];
  4.  
  5. fn reset(hm: &mut HashMap<String, Vec<i32>>) {
  6.     for (_key, value) in hm {
  7.         *value = ORIGIN.to_vec();
  8.     }
  9. }
  10.  
  11. fn reset_iter_mut(hm: &mut HashMap<String, Vec<i32>>) {
  12.     for (_key, value) in hm.iter_mut() {
  13.         *value = ORIGIN.to_vec();
  14.     }
  15. }
  16.  
  17. fn main() {
  18.     let mut a = HashMap::new();
  19.     a.insert("even".to_string(), vec![2, 4, 6]);
  20.     a.insert("odd".to_string(), vec![1, 3, 5]);
  21.     let mut b = a.clone();
  22.  
  23.     reset(&mut a);
  24.     reset_iter_mut(&mut b);
  25.  
  26.     assert_eq!(a, b);
  27.  
  28.     dbg!(a);
  29.     dbg!(b);
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top