Struct IntoIter
pub struct IntoIter<T, const N: usize> { pub(in ::array::iter) inner: ManuallyDrop<PolymorphicIter<[MaybeUninit<T>; N]>> }
A by-value [array] iterator.
Fields
inner: ManuallyDrop<PolymorphicIter<[MaybeUninit<T>; N]>>
Implementations
impl<T, const N: usize> IntoIter<T, N>
fn new(array: [T; N]) -> SelfCreates a new iterator over the given
array.const unsafe fn new_unchecked(buffer: [MaybeUninit<T>; N], initialized: Range<usize>) -> SelfCreates an iterator over the elements in a partially-initialized buffer.
If you have a fully-initialized array, then use
IntoIterator. But this is useful for returning partial results from unsafe code.Safety
- The
buffer[initialized]elements must all be initialized. - The range must be canonical, with
initialized.start <= initialized.end. - The range must be in-bounds for the buffer, with
initialized.end <= N. (Like how indexing[0][100..100]fails despite the range being empty.)
It's sound to have more elements initialized than mentioned, though that will most likely result in them being leaked.
Examples
use IntoIter; use MaybeUninit; # // Hi! Thanks for reading the code. This is restricted to `Copy` because # // otherwise it could leak. A fully-general version this would need a drop # // guard to handle panics from the iterator, but this works for an example. let r: = next_chunk.unwrap; assert_eq!; let r: = next_chunk.unwrap_err; assert_eq!;- The
const fn empty() -> SelfCreates an iterator over
Twhich returns no elements.If you just need an empty iterator, then use
iter::empty()instead. And if you need an empty array, use[].But this is useful when you need an
array::IntoIter<T, N>specifically.Examples
use IntoIter; let empty = empty; assert_eq!; assert_eq!; let empty = empty; assert_eq!;[1, 2].into_iter()and[].into_iter()have different types#![feature(array_into_iter_constructors)] use std::array::IntoIter; pub fn get_bytes(b: bool) -> IntoIter<i8, 4> { if b { [1, 2, 3, 4].into_iter() } else { [].into_iter() // error[E0308]: mismatched types } }But using this method you can get an empty iterator of appropriate size:
#![feature(array_into_iter_constructors)] use std::array::IntoIter; pub fn get_bytes(b: bool) -> IntoIter<i8, 4> { if b { [1, 2, 3, 4].into_iter() } else { IntoIter::empty() } } assert_eq!(get_bytes(true).collect::<Vec<_>>(), vec![1, 2, 3, 4]); assert_eq!(get_bytes(false).collect::<Vec<_>>(), vec![]);fn as_slice(&self) -> &[T]Returns an immutable slice of all elements that have not been yielded yet.
const fn as_mut_slice(&mut self) -> &mut [T]Returns a mutable slice of all elements that have not been yielded yet.
impl<T, const N: usize> IntoIter<T, N>
const fn unsize(&self) -> &PolymorphicIter<[MaybeUninit<T>]>const fn unsize_mut(&mut self) -> &mut PolymorphicIter<[MaybeUninit<T>]>
Trait Implementations
impl<T> OneShot for IntoIter<T, 0>
impl<T> OneShot for IntoIter<T, 1>
impl<T, const N: usize> Default for IntoIter<T, N>
fn default() -> Self
impl<T, const N: usize> DoubleEndedIterator for IntoIter<T, N>
fn next_back(&mut self) -> Option<Self::Item>fn rfold<Acc, Fold>(self, init: Acc, rfold: Fold) -> Acc where Fold: FnMut(Acc, Self::Item) -> Acc,fn try_rfold<B, F, R>(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
impl<T, const N: usize> Drop for IntoIter<T, N>
fn drop(&mut self)
impl<T, const N: usize> ExactSizeIterator for IntoIter<T, N>
fn len(&self) -> usizefn is_empty(&self) -> bool
impl<T, const N: usize> FusedIterator for IntoIter<T, N>
impl<T, const N: usize> Iterator for IntoIter<T, N>
type Item = T;fn next(&mut self) -> Option<Self::Item>fn size_hint(&self) -> (usize, Option<usize>)fn fold<Acc, Fold>(self, init: Acc, fold: Fold) -> Acc where Fold: FnMut(Acc, Self::Item) -> Acc,fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,fn count(self) -> usizefn last(self) -> Option<Self::Item>fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item
impl<T, const N: usize> TrustedLen for IntoIter<T, N>
impl<T, const N: usize> TrustedRandomAccessNoCoerce for IntoIter<T, N>
where
T: NonDrop,
const MAY_HAVE_SIDE_EFFECT: bool = false;
impl<T: Clone, const N: usize> Clone for IntoIter<T, N>
fn clone(&self) -> IntoIter<T, N>
impl<T: Debug, const N: usize> Debug for IntoIter<T, N>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Auto Trait Implementations
impl<T, const N: usize> Freeze for IntoIter<T, N>
where
ManuallyDrop<PolymorphicIter<[MaybeUninit<T>; N]>>: Freeze,
impl<T, const N: usize> RefUnwindSafe for IntoIter<T, N>
where
ManuallyDrop<PolymorphicIter<[MaybeUninit<T>; N]>>: RefUnwindSafe,
impl<T, const N: usize> Send for IntoIter<T, N>
where
ManuallyDrop<PolymorphicIter<[MaybeUninit<T>; N]>>: Send,
impl<T, const N: usize> Sync for IntoIter<T, N>
where
ManuallyDrop<PolymorphicIter<[MaybeUninit<T>; N]>>: Sync,
impl<T, const N: usize> Unpin for IntoIter<T, N>
where
ManuallyDrop<PolymorphicIter<[MaybeUninit<T>; N]>>: Unpin,
impl<T, const N: usize> UnsafeUnpin for IntoIter<T, N>
where
ManuallyDrop<PolymorphicIter<[MaybeUninit<T>; N]>>: UnsafeUnpin,
impl<T, const N: usize> UnwindSafe for IntoIter<T, N>
where
ManuallyDrop<PolymorphicIter<[MaybeUninit<T>; N]>>: UnwindSafe,
Blanket Implementations
impl<I> IntoIterator for IntoIter<T, N>
where
I: Iterator,
type Item = <I as Iterator>::Item;type IntoIter = I;fn into_iter(self) -> I
impl<T> Any for IntoIter<T, N>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for IntoIter<T, N>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for IntoIter<T, N>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for IntoIter<T, N>
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for IntoIter<T, N>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> SizeHint for IntoIter<T, N>
where
T: ?Sized,
fn lower_bound(&self) -> usizefn upper_bound(&self) -> Option<usize>
impl<T> SizedTypeProperties for IntoIter<T, N>
impl<T, U> Into<U> for IntoIter<T, N>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for IntoIter<T, N>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for IntoIter<T, N>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>