Struct PolymorphicIter

Source
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] and data[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,

Source

pub(super) const fn len(&self) -> usize

Source§

impl<T, const N: usize> PolymorphicIter<[MaybeUninit<T>; N]>

Source

pub(super) const fn empty() -> Self

Source

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>]>

Source

pub(super) fn as_slice(&self) -> &[T]

Source

pub(super) fn as_mut_slice(&mut self) -> &mut [T]

Source§

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).

Source

pub(super) fn next(&mut self) -> Option<T>

Source

pub(super) fn size_hint(&self) -> (usize, Option<usize>)

Source

pub(super) fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>

Source

pub(super) fn fold<B>(&mut self, init: B, f: impl FnMut(B, T) -> B) -> B

Source

pub(super) fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
where F: FnMut(B, T) -> R, R: Try<Output = B>,

Source

pub(super) fn next_back(&mut self) -> Option<T>

Source

pub(super) fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>

Source

pub(super) fn rfold<B>(&mut self, init: B, f: impl FnMut(B, T) -> B) -> B

Source

pub(super) fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R
where F: FnMut(B, T) -> R, R: Try<Output = B>,

Trait Implementations§

Source§

impl<T: Clone, const N: usize> Clone for PolymorphicIter<[MaybeUninit<T>; N]>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for PolymorphicIter<[MaybeUninit<T>]>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<DATA> Drop for PolymorphicIter<DATA>
where DATA: PartialDrop + ?Sized,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<DATA> Freeze for PolymorphicIter<DATA>
where DATA: Freeze + ?Sized,

§

impl<DATA> RefUnwindSafe for PolymorphicIter<DATA>
where DATA: RefUnwindSafe + ?Sized,

§

impl<DATA> Send for PolymorphicIter<DATA>
where DATA: Send + ?Sized,

§

impl<DATA> Sync for PolymorphicIter<DATA>
where DATA: Sync + ?Sized,

§

impl<DATA> Unpin for PolymorphicIter<DATA>
where DATA: Unpin + ?Sized,

§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)] const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)] const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

#[doc(hidden)] const MAX_SLICE_LEN: usize = _

🔬This is a nightly-only experimental API. (sized_type_properties)
The largest safe length for a [Self]. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.