Advertisement
cwchen

[Rust] Ownership issues in functions

Aug 27th, 2017
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.21 KB | None | 0 0
  1. fn main() {
  2. let v = vec![1, 2, 3];
  3.  
  4. // v is moved into do_nothing
  5. do_nothing(v);
  6.  
  7. // Error when accessing v
  8. println!("{}", v[1]);
  9. }
  10.  
  11. fn do_nothing(v: Vec<i32>) {
  12. // Do nothing here.
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement