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