use core::{cell::Cell, ffi::c_void, fmt, marker::PhantomData};
#[repr(transparent)]
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
pub struct JanetPointer {
pub(crate) inner: *mut c_void,
phatom: PhantomData<Cell<()>>,
}
impl JanetPointer {
#[inline]
pub const fn new(ptr: *mut c_void) -> Self {
Self {
inner: ptr,
phatom: PhantomData,
}
}
#[inline]
pub fn is_null(&self) -> bool {
self.inner.is_null()
}
#[inline]
pub const fn as_ptr(self) -> *mut c_void {
self.inner
}
#[inline]
pub const fn cast<U>(self) -> *mut U {
self.inner as *mut U
}
}
impl fmt::Debug for JanetPointer {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&self.as_ptr(), f)
}
}
impl fmt::Pointer for JanetPointer {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Pointer::fmt(&self.as_ptr(), f)
}
}