use core::marker::PhantomData;
use core::ptr::NonNull;
pub(crate) struct InChunk<T: ?Sized> {
ptr: NonNull<T>,
_phantom: PhantomData<*const T>,
}
impl<T: ?Sized> Clone for InChunk<T> {
#[inline]
#[cfg_attr(coverage_nightly, coverage(off))]
fn clone(&self) -> Self {
*self
}
}
impl<T: ?Sized> Copy for InChunk<T> {}
impl<T: ?Sized> InChunk<T> {
#[inline]
pub(super) fn from_raw(ptr: NonNull<T>) -> Self {
Self {
ptr,
_phantom: PhantomData,
}
}
#[inline]
pub(crate) fn as_ptr(self) -> *mut T {
self.ptr.as_ptr()
}
#[inline]
pub(crate) fn as_non_null(self) -> NonNull<T> {
self.ptr
}
}
impl<T: ?Sized> InChunk<T> {
#[inline]
pub(crate) fn cast<U>(self) -> InChunk<U> {
InChunk {
ptr: self.ptr.cast(),
_phantom: PhantomData,
}
}
}
impl InChunk<u8> {
#[inline]
pub(crate) fn addr(self) -> usize {
self.ptr.as_ptr() as usize
}
#[inline]
pub(crate) fn into_slice<T>(self, len: usize) -> InChunk<[T]> {
let slice = NonNull::slice_from_raw_parts(self.ptr.cast::<T>(), len);
InChunk {
ptr: slice,
_phantom: PhantomData,
}
}
}