pub(super) struct PolymorphicIter<DATA>where
DATA: PartialDrop + ?Sized,{
alive: IndexRange,
data: DATA,
}
Expand description
The internals of a by-value array iterator.
The real array::IntoIter<T, N>
stores a PolymorphicIter<[MaybeUninit<T>, N]>
which it unsizes to PolymorphicIter<[MaybeUninit<T>]>
to iterate.
Fields§
§alive: IndexRange
The elements in data
that have not been yielded yet.
Invariants:
alive.end <= N
(And the IndexRange
type requires alive.start <= alive.end
.)
data: DATA
This is the array we are iterating over.
Elements with index i
where alive.start <= i < alive.end
have not
been yielded yet and are valid array entries. Elements with indices i < alive.start
or i >= alive.end
have been yielded already and must
not be accessed anymore! Those dead elements might even be in a
completely uninitialized state!
So the invariants are:
data[alive]
is alive (i.e. contains valid elements)data[..alive.start]
anddata[alive.end..]
are dead (i.e. the elements were already read and must not be touched anymore!)
Implementations§
Source§impl<DATA> PolymorphicIter<DATA>where
DATA: PartialDrop + ?Sized,
impl<DATA> PolymorphicIter<DATA>where
DATA: PartialDrop + ?Sized,
Source§impl<T, const N: usize> PolymorphicIter<[MaybeUninit<T>; N]>
impl<T, const N: usize> PolymorphicIter<[MaybeUninit<T>; N]>
pub(super) const fn empty() -> Self
Sourcepub(super) const unsafe fn new_unchecked(
alive: IndexRange,
data: [MaybeUninit<T>; N],
) -> Self
pub(super) const unsafe fn new_unchecked( alive: IndexRange, data: [MaybeUninit<T>; N], ) -> Self
§Safety
data[alive]
are all initialized.
Source§impl<T> PolymorphicIter<[MaybeUninit<T>]>
impl<T> PolymorphicIter<[MaybeUninit<T>]>
Source§impl<T> PolymorphicIter<[MaybeUninit<T>]>
Iterator-equivalent methods.
impl<T> PolymorphicIter<[MaybeUninit<T>]>
Iterator-equivalent methods.
We don’t implement the actual iterator traits because we want to implement
things like try_fold
that require Self: Sized
(which we’re not).
pub(super) fn next(&mut self) -> Option<T>
pub(super) fn size_hint(&self) -> (usize, Option<usize>)
pub(super) fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
pub(super) fn fold<B>(&mut self, init: B, f: impl FnMut(B, T) -> B) -> B
pub(super) fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
pub(super) fn next_back(&mut self) -> Option<T>
pub(super) fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
pub(super) fn rfold<B>(&mut self, init: B, f: impl FnMut(B, T) -> B) -> B
pub(super) fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
Trait Implementations§
Source§impl<T: Clone, const N: usize> Clone for PolymorphicIter<[MaybeUninit<T>; N]>
impl<T: Clone, const N: usize> Clone for PolymorphicIter<[MaybeUninit<T>; N]>
Source§impl<T: Debug> Debug for PolymorphicIter<[MaybeUninit<T>]>
impl<T: Debug> Debug for PolymorphicIter<[MaybeUninit<T>]>
Source§impl<DATA> Drop for PolymorphicIter<DATA>where
DATA: PartialDrop + ?Sized,
impl<DATA> Drop for PolymorphicIter<DATA>where
DATA: PartialDrop + ?Sized,
Auto Trait Implementations§
impl<DATA> Freeze for PolymorphicIter<DATA>
impl<DATA> RefUnwindSafe for PolymorphicIter<DATA>where
DATA: RefUnwindSafe + ?Sized,
impl<DATA> Send for PolymorphicIter<DATA>
impl<DATA> Sync for PolymorphicIter<DATA>
impl<DATA> Unpin for PolymorphicIter<DATA>
impl<DATA> UnsafeUnpin for PolymorphicIter<DATA>where
DATA: UnsafeUnpin + ?Sized,
impl<DATA> UnwindSafe for PolymorphicIter<DATA>where
DATA: UnwindSafe + ?Sized,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)] const IS_ZST: bool = _
#[doc(hidden)] const IS_ZST: bool = _
sized_type_properties
)Source§#[doc(hidden)] const LAYOUT: Layout = _
#[doc(hidden)] const LAYOUT: Layout = _
sized_type_properties
)Source§#[doc(hidden)] const MAX_SLICE_LEN: usize = _
#[doc(hidden)] const MAX_SLICE_LEN: usize = _
sized_type_properties
)[Self]
. Read more