Advertisement
cwchen

[Rust] Modifying a vector in-place

Aug 27th, 2017
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.23 KB | None | 0 0
  1. fn main() {
  2.     let mut vec = vec![1, 2, 3];
  3.  
  4.     // Modify vec in-place!
  5.     for item in vec.iter_mut() {
  6.         *item = (*item) * (*item);
  7.     }
  8.  
  9.     // Print out the data of vec in console
  10.     println!("{:?}", vec);
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement