Guest User

Untitled

a guest
Jan 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. fn main() {
  2. let s = "".to_owned();
  3. {
  4. let _t = &s;
  5. let _t2 = &s;
  6. let _t3 = &_t;
  7. let mut _t4 = &s;
  8. }
  9. }
  10.  
  11. pub struct Borrowing();
  12.  
  13. // function takes ownership of `var`:
  14. // this means that var can no longer be
  15. // used back in the function that called `borrowing`.
  16. pub fn borrowing(_var: Borrowing){}
  17. // borrows `var`: this means that `borrowing2` has
  18. // access to this variable but does not have ownership;
  19. // `var` can be reused in its original context
  20. pub fn borrowing2(_var: &Borrowing){}
  21. // mutably borrows `var`: this means that the variable
  22. // can be mutated and that the variable will be able to
  23. // be used in its original context. NOTE: that a variable
  24. // can only have a single mutable reference at a time;
  25. // this also means that there cannot be immutable references
  26. // at the same time.
  27. pub fn borrowing3(_var: &mut Borrowing){}
Add Comment
Please, Sign In to add comment