[−][src]Function fuckit::grapple
pub unsafe fn grapple<T>(pointer: &T) -> &'static mut T
Given any pointer, even an immutable one with a short lifetime, returns a
mutable pointer of unbounded 'static
lifetime to the same underlying
address.
Safety
"Abandon all hope, ye who enter here."
Safe Alternative
Declare an
Rc<RefCell<T>>
in your main or somewhere else near the bottom of your stack, and pass
that around.
Example
Interwoven use of two aliased mutable references:
let mut original = vec![1, 2, 3, 4, 5]; let handle = unsafe { fuckit::grapple(&original) }; original[4] = 1; handle[0] = 5; original[3] = 2; handle[1] = 4; assert_eq!(original, vec![5, 4, 3, 2, 1]); assert_eq!(original, *handle);