I propose to add a new function as_borowed_mut
that has a signature of as_borowed_mut<'a,T,U>( src:*mut ,from:&'a mut U) ->&'a mut T
. This function as the existing function as_mut
does but prevents the use of the original reference until the old one is dropped.
example:
let x:usize = 10;
let y = &mut x;
let z = as_borowed_mut(y as *mut usize,y);
*y; //fails because x is mutably borrowed by z
drop(z);
*y;//works