A function `as_borowed_mut` for pointers

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.


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

What is the benefit of this? And how will it be implemented?

error: expected type, found `,`
 --> src/lib.rs:2:34
2 | as_borowed_mut<'a,T,U>( src:*mut ,from:&'a mut U) ->&'a mut T
  |                                  ^ expected type

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.