Struct IntoIter
struct IntoIter<T, N: usize> { ... }
A by-value [array] iterator.
Implementations
impl<T, N: usize> IntoIter<T, N>
fn new(array: [T; N]) -> SelfCreates a new iterator over the given
array.unsafe const 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: &Self) -> &[T]Returns an immutable slice of all elements that have not been yielded yet.
fn as_mut_slice(self: &mut Self) -> &mut [T]Returns a mutable slice of all elements that have not been yielded yet.
impl<I> IntoIterator for IntoIter<T, N>
fn into_iter(self: Self) -> I
impl<T> Any for IntoIter<T, N>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for IntoIter<T, N>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for IntoIter<T, N>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for IntoIter<T, N>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for IntoIter<T, N>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, N: usize> Default for IntoIter<T, N>
fn default() -> Self
impl<T, N: usize> DoubleEndedIterator for IntoIter<T, N>
fn next_back(self: &mut Self) -> Option<<Self as >::Item>fn rfold<Acc, Fold>(self: Self, init: Acc, rfold: Fold) -> Acc where Fold: FnMut(Acc, <Self as >::Item) -> Accfn try_rfold<B, F, R>(self: &mut Self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, <Self as >::Item) -> R, R: Try<Output = B>fn advance_back_by(self: &mut Self, n: usize) -> Result<(), NonZero<usize>>
impl<T, N: usize> Drop for IntoIter<T, N>
fn drop(self: &mut Self)
impl<T, N: usize> ExactSizeIterator for IntoIter<T, N>
fn len(self: &Self) -> usizefn is_empty(self: &Self) -> bool
impl<T, N: usize> Freeze for IntoIter<T, N>
impl<T, N: usize> FusedIterator for IntoIter<T, N>
impl<T, N: usize> Iterator for IntoIter<T, N>
fn next(self: &mut Self) -> Option<<Self as >::Item>fn size_hint(self: &Self) -> (usize, Option<usize>)fn fold<Acc, Fold>(self: Self, init: Acc, fold: Fold) -> Acc where Fold: FnMut(Acc, <Self as >::Item) -> Accfn try_fold<B, F, R>(self: &mut Self, init: B, f: F) -> R where Self: Sized, F: FnMut(B, <Self as >::Item) -> R, R: Try<Output = B>fn count(self: Self) -> usizefn last(self: Self) -> Option<<Self as >::Item>fn advance_by(self: &mut Self, n: usize) -> Result<(), NonZero<usize>>
impl<T, N: usize> RefUnwindSafe for IntoIter<T, N>
impl<T, N: usize> Send for IntoIter<T, N>
impl<T, N: usize> Sync for IntoIter<T, N>
impl<T, N: usize> TrustedLen for IntoIter<T, N>
impl<T, N: usize> Unpin for IntoIter<T, N>
impl<T, N: usize> UnsafeUnpin for IntoIter<T, N>
impl<T, N: usize> UnwindSafe for IntoIter<T, N>
impl<T, U> Into for IntoIter<T, N>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for IntoIter<T, N>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for IntoIter<T, N>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: $crate::clone::Clone, N: usize> Clone for IntoIter<T, N>
fn clone(self: &Self) -> IntoIter<T, N>
impl<T: fmt::Debug, N: usize> Debug for IntoIter<T, N>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result