Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- let s = "".to_owned();
- {
- let _t = &s;
- let _t2 = &s;
- let _t3 = &_t;
- let mut _t4 = &s;
- }
- }
- pub struct Borrowing();
- // function takes ownership of `var`:
- // this means that var can no longer be
- // used back in the function that called `borrowing`.
- pub fn borrowing(_var: Borrowing){}
- // borrows `var`: this means that `borrowing2` has
- // access to this variable but does not have ownership;
- // `var` can be reused in its original context
- pub fn borrowing2(_var: &Borrowing){}
- // mutably borrows `var`: this means that the variable
- // can be mutated and that the variable will be able to
- // be used in its original context. NOTE: that a variable
- // can only have a single mutable reference at a time;
- // this also means that there cannot be immutable references
- // at the same time.
- pub fn borrowing3(_var: &mut Borrowing){}
Add Comment
Please, Sign In to add comment