Advertisement
cwchen

[Rust] Lifetime error demo

Aug 27th, 2017
1,487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.25 KB | None | 0 0
  1. fn main() {
  2.     let x;
  3.  
  4.     {
  5.         let n = 5;
  6.  
  7.         // Borrow n to y
  8.         let y = &n;
  9.  
  10.         // Transfer the ownership from y to x
  11.         x = y;
  12.      } // n lives until here
  13.  
  14.      // n is no longer available.
  15.      println!("{}", x);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement