il2cpp_bridge_rs/structs/
ptr.rs1use std::ops::{Deref, DerefMut};
7
8#[repr(transparent)]
10#[derive(Debug, Clone, Copy)]
11pub struct MutPtr<T>(pub *mut T);
12
13impl<T> MutPtr<T> {
14 #[inline(always)]
16 pub fn new(ptr: *mut T) -> Self {
17 Self(ptr)
18 }
19
20 #[inline(always)]
22 pub fn is_null(&self) -> bool {
23 self.0.is_null()
24 }
25
26 #[inline(always)]
28 pub fn as_ptr(&self) -> *mut T {
29 self.0
30 }
31}
32
33impl<T> Deref for MutPtr<T> {
34 type Target = T;
35
36 #[inline(always)]
38 fn deref(&self) -> &Self::Target {
39 if self.0.is_null() {
40 panic!("Null pointer dereference: {}", std::any::type_name::<T>());
41 }
42 unsafe { &*self.0 }
43 }
44}
45
46impl<T> DerefMut for MutPtr<T> {
47 #[inline(always)]
49 fn deref_mut(&mut self) -> &mut Self::Target {
50 if self.0.is_null() {
51 panic!("Null pointer dereference: {}", std::any::type_name::<T>());
52 }
53 unsafe { &mut *self.0 }
54 }
55}