chj_rustbin/util/
statify.rs

1/// Make the lifetime of a reference static. Be very careful with your
2/// reasoning why your usage doesn't introduce UB!
3pub unsafe fn statify<T>(r: &T) -> &'static T {
4    let ptr: *const T = r;
5    &*ptr
6}
7
8/// Same as `statify` but for mutable references.
9pub unsafe fn statify_mut<T>(r: &mut T) -> &'static mut T {
10    let ptr: *mut T = r;
11    &mut *ptr
12}