daily pastebin goal
43%
SHARE
TWEET

[Rust] Modifying a vector in-place

cwchen Aug 27th, 2017 258 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
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
 
Top