Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn wtf(vector: &mut Vec<i32>) { // mutable borrow starts here
- vector.push(20)
- } // mutable borrow also ends here
- fn main() {
- let mut p: Vec<i32> = vec![1, 2, 3];
- {
- let x = &mut p; // lifetime of mutable borrow starts here
- x.push(42);
- } // life-time of x ends here
- wtf(&mut p);
- println!("{:?}", p); // & to P...we have one mutable ref, one immutable ref
- //-- why no compile time error???
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement