#![no_std]
#![warn(missing_docs)]
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(transparent)]
pub struct MutPtrIter<T>(*mut T);
impl<T> Iterator for MutPtrIter<T> {
type Item = *mut T;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
let out = self.0;
self.0 = unsafe { self.0.add(1) };
Some(out)
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(usize::MAX, None)
}
}
impl<T> MutPtrIter<T> {
#[inline]
pub unsafe fn over_slice_ptr(p: *mut [T]) -> core::iter::Take<Self> {
let len: usize = core::ptr::NonNull::new_unchecked(p).len();
Self(p as *mut T).take(len)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[repr(transparent)]
pub struct ConstPtrIter<T>(*const T);
impl<T> Iterator for ConstPtrIter<T> {
type Item = *const T;
#[inline]
fn next(&mut self) -> Option<Self::Item> {
let out = self.0;
self.0 = unsafe { self.0.add(1) };
Some(out)
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
(usize::MAX, None)
}
}
impl<T> ConstPtrIter<T> {
#[inline]
pub unsafe fn over_slice_ptr(p: *const [T]) -> core::iter::Take<Self> {
let len: usize = core::ptr::NonNull::new_unchecked(p as *mut [T]).len();
Self(p as *const T).take(len)
}
#[inline]
pub unsafe fn read_until_default(
p: *const T,
) -> impl Iterator<Item = T> + Clone
where
T: Copy + Default + PartialEq,
{
Self(p).map(|p| unsafe { *p }).take_while(|p| p != &T::default())
}
}