1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
To be used later on, I prefer focusing on the RawPtr
*/
/*
use std::marker::PhantomData;
use std::mem::{transmute, transmute_copy};
use crate::unsafe_std::ptrs::raw_ptr::RawPtr;
#[repr(transparent)]
#[derive(Copy, Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
pub struct RawConstPtr<T> {
ptr: *const T,
_marker: PhantomData<T>,
}
impl<T> RawConstPtr<T> {
const NULL: RawConstPtr<T> = RawConstPtr::null();
#[inline(always)]
pub const fn new(value: &T) -> RawConstPtr<T> {
Self {
ptr: value as *const T,
_marker: PhantomData,
}
}
#[inline(always)]
pub const fn null() -> RawConstPtr<T> {
Self {
ptr: std::ptr::null_mut(),
_marker: PhantomData,
}
}
#[inline(always)]
pub const unsafe fn index(&self, index: isize) -> &T {
&*self.ptr.offset(index)
}
#[inline(always)]
pub const fn is_null(&self) -> bool {
self.ptr.is_null()
}
#[inline(always)]
pub const unsafe fn as_ref(&self) -> Option<&T> {
self.ptr.as_ref()
}
#[inline(always)]
pub const unsafe fn as_const_raw(&self) -> Option<*const T> {
if self.ptr.is_null() {
None
} else {
Some(self.ptr as *const T)
}
}
#[inline(always)]
pub const unsafe fn const_cast_mut(self) -> RawPtr<T> {
transmute(self)
}
#[inline(always)]
pub const unsafe fn cast<U>(self) -> RawConstPtr<U> {
transmute(self)
}
#[inline(always)]
pub const unsafe fn cast_ref<U>(&self) -> &U {
transmute(self.ptr as *const U)
}
#[inline(always)]
pub const unsafe fn cast_const_raw<U>(&mut self) -> *const U {
transmute(self.ptr)
}
}*/