unsafe_utilities/
to_ref.rs

1/// Accessing nested pointers is so annoying in Rust. Use for to make process a lot less annoying.
2pub trait ToReference<T> {
3    unsafe fn to_ref(self) -> T;
4}
5
6impl<'a, T> ToReference<&'a T> for *const T {
7    #[inline]
8    unsafe fn to_ref(self) -> &'a T {
9        &*self
10    }
11}
12
13impl<'a, T> ToReference<&'a mut T> for *mut T {
14    #[inline]
15    unsafe fn to_ref(self) -> &'a mut T {
16        &mut *self
17    }
18}
19
20impl<'a, T> ToReference<&'a [T]> for *const [T] {
21    #[inline]
22    unsafe fn to_ref(self) -> &'a [T] {
23        &*self
24    }
25}
26
27impl<'a, T> ToReference<&'a mut [T]> for *mut [T] {
28    #[inline]
29    unsafe fn to_ref(self) -> &'a mut [T] {
30        &mut *self
31    }
32}