Advertisement
mbazs

Rust move

Mar 14th, 2019
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.29 KB | None | 0 0
  1. fn main() {
  2.     let mut v = vec![1,2,3,4,5];                  
  3.     v = vec_swap(v);
  4.     v[0] = 55;
  5.     println!("{:?}", v);
  6. }
  7.  
  8. fn vec_swap<T: Copy>(mut v: Vec<T>) -> Vec<T> {  
  9.     if v.len() >= 2 {
  10.         let tmp = v[0];
  11.         v[0] = v[1];
  12.         v[1] = tmp;
  13.     }
  14.     v
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement