Advertisement
cwchen

[Rust] Borrowing demo (with error)

Aug 27th, 2017
518
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 v = vec![1, 2, 3];
  3.  
  4.     // Try to modify vec in-place
  5.     square_each(& v);
  6.  
  7.     println!("{}", v[1]);
  8. }
  9.  
  10. fn square_each(v: & Vec<i32>) {
  11.     for e in v.iter_mut() {
  12.         *e = (*e) * (*e);
  13.     }
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement