SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use std::fmt::Display;
  2.  
  3. fn main() {
  4.     let mut v = vec![1,2,3];
  5.     do_bad_stuff(&mut v);
  6.     print_elements(&v);
  7. }
  8.  
  9. fn print_elements<T>(v: &[T])
  10.     where T: Display
  11. {
  12.     for (i, element) in v.iter().enumerate() {
  13.         println!("[{}] = {}", i, element);
  14.     }
  15. }
  16.  
  17. fn do_bad_stuff<T>(v: &mut[T]) {
  18.     let v2 = &mut v[1..];
  19.     v2.swap(0, 1);
  20.    
  21.     let v3 = &mut v[1..];
  22.     v3.swap(0, 1);
  23.  
  24.     v.swap(0, 1);
  25. }
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