make x::null const

This commit is contained in:
2024-09-30 19:14:11 -04:00
parent 27d2c4707b
commit ec87c5398d
2 changed files with 5 additions and 5 deletions

View File

@@ -12,5 +12,5 @@ proc-macro = true
[dependencies] [dependencies]
quote = "1" quote = "1"
proc-macro2 = "1.0.66" proc-macro2 = "1.0.66"
syn = { version = "2.0.66", features = ["full"] } syn = { version = "2.0.48", features = ["full"] }

View File

@@ -1,5 +1,5 @@
pub fn null<T: internal::Pointer>() -> T { T::new_null() } pub const fn null<T: internal::Pointer>() -> T { T::NULL }
pub fn iterate<T: internal::Pointer>(pointer: T) -> T::IterType { pub fn iterate<T: internal::Pointer>(pointer: T) -> T::IterType {
pointer.into_iter() pointer.into_iter()
} }
@@ -9,8 +9,8 @@ mod internal {
pub trait Pointer { pub trait Pointer {
type IterType; type IterType;
const NULL: Self;
fn into_iter(self) -> Self::IterType; fn into_iter(self) -> Self::IterType;
fn new_null() -> Self;
} }
@@ -40,14 +40,14 @@ mod internal {
} }
impl<T> Pointer for *const T { impl<T> Pointer for *const T {
type IterType = PIter<T>; type IterType = PIter<T>;
const NULL: Self = core::ptr::null();
fn into_iter(self) -> Self::IterType { PIter(self) } fn into_iter(self) -> Self::IterType { PIter(self) }
fn new_null() -> Self { core::ptr::null() }
} }
impl<T> Pointer for *mut T { impl<T> Pointer for *mut T {
type IterType = PIterMut<T>; type IterType = PIterMut<T>;
const NULL: Self = core::ptr::null_mut();
fn into_iter(self) -> Self::IterType { PIterMut(self) } fn into_iter(self) -> Self::IterType { PIterMut(self) }
fn new_null() -> Self { core::ptr::null_mut() }
} }
} }