Failed to get address in while loop
The Rust Programming Language Forum
Failed to get address in while loop
Why can't I get address in the while loop? struct Foo { elem1: u32, elem2: String, } fn demo1(x: &mut Foo) { let ref_1 = &mut x.elem1; let ref_2 = &mut x.elem2; let ptr_x = x as *mut Foo; // Ok! } fn demo2(x: &mut Foo) { let ref_1 = &mut x.elem1; while *ref_1 < 20 { let ptr_x1 = x as *mut Foo; // Failed: cannot borrow *x as mutable more than once at a time // let ptr_x2 = std::ptr::addr_of_mut!(x); // Failed: cannot borrow x as mutable more than once ...
0 comments
No comments yet.