Advertisement
cwchen

[Rust] Changing data in a vector with indexs.

Aug 22nd, 2017
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.20 KB | None | 0 0
  1. fn main() {
  2.     let mut vec = vec![1, 2, 3];
  3.  
  4.     for i in 0..vec.len() {
  5.         vec[i] = vec[i] * vec[i];
  6.     }
  7.  
  8.     assert_eq!(vec[0], 1);
  9.     assert_eq!(vec[1], 4);
  10.     assert_eq!(vec[2], 9);
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement