pub struct IntoIterusize> { /* private fields */ }
Expand description
A by-value array iterator.
Implementations§
Source§implusize> IntoIter
implusize> IntoIter
1.51.0 · Sourcepub fn new(array: [T; N]) -> IntoIter ⓘ
👎Deprecated since 1.59.0: use IntoIterator::into_iter
instead
pub fn new(array: [T; N]) -> IntoIter ⓘ
IntoIterator::into_iter
insteadCreates a new iterator over the given array
.
Sourcepub const unsafe fn new_unchecked(
buffer: [MaybeUninit; N],
initialized: Range<usize>,
) -> IntoIter ⓘ
🔬This is a nightly-only experimental API. (array_into_iter_constructors
#91583)
pub const unsafe fn new_unchecked(
buffer: [MaybeUninit; N],
initialized: Range<usize>,
) -> IntoIter ⓘ
array_into_iter_constructors
#91583)Creates 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
#![feature(array_into_iter_constructors)]
#![feature(maybe_uninit_uninit_array_transpose)]
use std::array::IntoIter;
use std::mem::MaybeUninit;
fn next_chunkconst N: usize>(
it: &mut impl Iterator- ,
) -> Result<[T; N], IntoIter
> {
let mut buffer = [const { MaybeUninit::uninit() }; N];
let mut i = 0;
while i < N {
match it.next() {
Some(x) => {
buffer[i].write(x);
i += 1;
}
None => {
// SAFETY: We've initialized the first `i` items
unsafe {
return Err(IntoIter::new_unchecked(buffer, 0..i));
}
}
}
}
// SAFETY: We've initialized all N items
unsafe { Ok(buffer.transpose().assume_init()) }
}
let r: [_; 4] = next_chunk(&mut (10..16)).unwrap();
assert_eq!(r, [10, 11, 12, 13]);
let r: IntoIter<_, 40> = next_chunk(&mut (10..16)).unwrap_err();
assert_eq!(r.collect::_>>(), vec![10, 11, 12, 13, 14, 15]);
Sourcepub const fn empty() -> IntoIter ⓘ
🔬This is a nightly-only experimental API. (array_into_iter_constructors
#91583)
pub const fn empty() -> IntoIter ⓘ
array_into_iter_constructors
#91583)Creates an iterator over T
which 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
specifically.
§Examples
#![feature(array_into_iter_constructors)]
use std::array::IntoIter;
let empty = IntoIter::3>::empty();
assert_eq!(empty.len(), 0);
assert_eq!(empty.as_slice(), &[]);
let empty = IntoIter::200>::empty();
assert_eq!(empty.len(), 0);
[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 {
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) -> IntoIter4> {
if b {
[1, 2, 3, 4].into_iter()
} else {
IntoIter::empty()
}
}
assert_eq!(get_bytes(true).collect::_>>(), vec![1, 2, 3, 4]);
assert_eq!(get_bytes(false).collect::_>>(), vec![]);
1.51.0 · Sourcepub fn as_slice(&self) -> &[T]
pub fn as_slice(&self) -> &[T]
Returns an immutable slice of all elements that have not been yielded yet.
1.51.0 · Sourcepub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_mut_slice(&mut self) -> &mut [T]
Returns a mutable slice of all elements that have not been yielded yet.
Trait Implementations§
1.40.0 · Source§implusize> DoubleEndedIterator for IntoIter
implusize> DoubleEndedIterator for IntoIter
Source§fn next_back(&mut self) -> Option<<IntoIter as Iterator>::Item>
fn next_back(&mut self) -> Option<<IntoIter as Iterator>::Item>
Source§fn rfold(self, init: Acc, rfold: Fold) -> Acc
fn rfold(self, init: Acc, rfold: Fold) -> Acc
Source§fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
iter_advance_by
#77404)n
elements. Read more1.37.0 · Source§fn nth_back(&mut self, n: usize) -> OptionItem>
fn nth_back(&mut self, n: usize) -> OptionItem>
n
th element from the end of the iterator. Read more1.27.0 · Source§fn try_rfold(&mut self, init: B, f: F) -> R
fn try_rfold(&mut self, init: B, f: F) -> R
Iterator::try_fold()
: it takes
elements starting from the back of the iterator. Read more1.40.0 · Source§implusize> ExactSizeIterator for IntoIter
implusize> ExactSizeIterator for IntoIter
1.40.0 · Source§implusize> Iterator for IntoIter
implusize> Iterator for IntoIter
Source§fn next(&mut self) -> Option<<IntoIter as Iterator>::Item>
fn next(&mut self) -> Option<<IntoIter as Iterator>::Item>
Source§fn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Source§fn fold(self, init: Acc, fold: Fold) -> Acc
fn fold(self, init: Acc, fold: Fold) -> Acc
Source§fn count(self) -> usize
fn count(self) -> usize
Source§fn last(self) -> Option<<IntoIter as Iterator>::Item>
fn last(self) -> Option<<IntoIter as Iterator>::Item>
Source§fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>
iter_advance_by
#77404)n
elements. Read moreSource§fn next_chunkusize>(
&mut self,
) -> Result<[Self::Item; N], IntoIterItem, N>>where
Self: Sized,
fn next_chunkusize>(
&mut self,
) -> Result<[Self::Item; N], IntoIterItem, N>>where
Self: Sized,
iter_next_chunk
#98326)N
values. Read more1.0.0 · Source§fn nth(&mut self, n: usize) -> OptionItem>
fn nth(&mut self, n: usize) -> OptionItem>
n
th element of the iterator. Read more1.28.0 · Source§fn step_by(self, step: usize) -> StepBy ⓘwhere
Self: Sized,
fn step_by(self, step: usize) -> StepBy ⓘwhere
Self: Sized,
1.0.0 · Source§fn chain(self, other: U) -> ChainIntoIterator>::IntoIter> ⓘ
fn chain(self, other: U) -> ChainIntoIterator>::IntoIter> ⓘ
1.0.0 · Source§fn zip(self, other: U) -> ZipIntoIterator>::IntoIter> ⓘwhere
Self: Sized,
U: IntoIterator,
fn zip(self, other: U) -> ZipIntoIterator>::IntoIter> ⓘwhere
Self: Sized,
U: IntoIterator,
Source§fn intersperse(self, separator: Self::Item) -> Intersperse ⓘ
fn intersperse(self, separator: Self::Item) -> Intersperse ⓘ
iter_intersperse
#79524)separator
between adjacent
items of the original iterator. Read moreSource§fn intersperse_with(self, separator: G) -> IntersperseWith ⓘ
fn intersperse_with(self, separator: G) -> IntersperseWith ⓘ
iter_intersperse
#79524)separator
between adjacent items of the original iterator. Read more1.0.0 · Source§fn map(self, f: F) -> Map ⓘ
fn map(self, f: F) -> Map ⓘ
1.0.0 · Source§fn filter
fn filter
1.0.0 · Source§fn filter_map(self, f: F) -> FilterMap ⓘ
fn filter_map(self, f: F) -> FilterMap ⓘ
1.0.0 · Source§fn enumerate(self) -> Enumerate ⓘwhere
Self: Sized,
fn enumerate(self) -> Enumerate ⓘwhere
Self: Sized,
1.0.0 · Source§fn skip_while
fn skip_while
1.0.0 · Source§fn take_while
fn take_while
1.57.0 · Source§fn map_while(self, predicate: P) -> MapWhile ⓘ
fn map_while(self, predicate: P) -> MapWhile ⓘ
1.0.0 · Source§fn skip(self, n: usize) -> Skip ⓘwhere
Self: Sized,
fn skip(self, n: usize) -> Skip ⓘwhere
Self: Sized,
n
elements. Read more1.0.0 · Source§fn take(self, n: usize) -> Take ⓘwhere
Self: Sized,
fn take(self, n: usize) -> Take ⓘwhere
Self: Sized,
n
elements, or fewer
if the underlying iterator ends sooner. Read more1.0.0 · Source§fn flat_map(self, f: F) -> FlatMap ⓘ
fn flat_map(self, f: F) -> FlatMap ⓘ
1.29.0 · Source§fn flatten(self) -> Flatten ⓘ
fn flatten(self) -> Flatten ⓘ
Source§fn map_windowsusize>(self, f: F) -> MapWindows ⓘ
fn map_windowsusize>(self, f: F) -> MapWindows ⓘ
iter_map_windows
#87155)f
for each contiguous window of size N
over
self
and returns an iterator over the outputs of f
. Like slice::windows()
,
the windows during mapping overlap as well. Read more1.0.0 · Source§fn inspect(self, f: F) -> Inspect ⓘ
fn inspect(self, f: F) -> Inspect ⓘ
1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Iterator
. Read more1.0.0 · Source§fn collect(self) -> Bwhere
B: FromIteratorItem>,
Self: Sized,
fn collect(self) -> Bwhere
B: FromIteratorItem>,
Self: Sized,
Source§fn try_collect(
&mut self,
) -> <Item as Try>::Residual as Residual>::TryType
fn try_collect(
&mut self,
) -> <Item as Try>::Residual as Residual>::TryType
iterator_try_collect
#94047)Source§fn collect_into(self, collection: &mut E) -> &mut E
fn collect_into(self, collection: &mut E) -> &mut E
iter_collect_into
#94780)1.0.0 · Source§fn partition(self, f: F) -> (B, B)
fn partition(self, f: F) -> (B, B)
Source§fn partition_in_place<'a, T, P>(self, predicate: P) -> usize
fn partition_in_place<'a, T, P>(self, predicate: P) -> usize
iter_partition_in_place
#62543)true
precede all those that return false
.
Returns the number of true
elements found. Read moreSource§fn is_partitioned
(self, predicate: P) -> bool
fn is_partitioned
(self, predicate: P) -> bool
iter_is_partitioned
#62544)true
precede all those that return false
. Read more1.27.0 · Source§fn try_fold(&mut self, init: B, f: F) -> R
fn try_fold(&mut self, init: B, f: F) -> R
1.27.0 · Source§fn try_for_each(&mut self, f: F) -> R
fn try_for_each(&mut self, f: F) -> R
1.51.0 · Source§fn reduce(self, f: F) -> OptionItem>
fn reduce(self, f: F) -> OptionItem>
Source§fn try_reduce(
&mut self,
f: impl FnMut(Self::Item, Self::Item) -> R,
) -> <Try>::Residual as Residual<Option<Try>::Output>>>::TryType
fn try_reduce(
&mut self,
f: impl FnMut(Self::Item, Self::Item) -> R,
) -> <Try>::Residual as Residual<Option<Try>::Output>>>::TryType
iterator_try_reduce
#87053)1.0.0 · Source§fn all(&mut self, f: F) -> bool
fn all(&mut self, f: F) -> bool
1.0.0 · Source§fn any(&mut self, f: F) -> bool
fn any(&mut self, f: F) -> bool
1.0.0 · Source§fn find
(&mut self, predicate: P) -> OptionItem>
fn find
(&mut self, predicate: P) -> Option
1.30.0 · Source§fn find_map(&mut self, f: F) -> Option
fn find_map(&mut self, f: F) -> Option
Source§fn try_find(
&mut self,
f: impl FnMut(&Self::Item) -> R,
) -> <Try>::Residual as Residual<OptionItem>>>::TryType
fn try_find(
&mut self,
f: impl FnMut(&Self::Item) -> R,
) -> <Try>::Residual as Residual<OptionItem>>>::TryType
try_find
#63178)1.0.0 · Source§fn rposition
fn rposition
1.6.0 · Source§fn max_by_key(self, f: F) -> OptionItem>
fn max_by_key(self, f: F) -> OptionItem>
1.15.0 · Source§fn max_by(self, compare: F) -> OptionItem>
fn max_by(self, compare: F) -> OptionItem>
1.6.0 · Source§fn min_by_key(self, f: F) -> OptionItem>
fn min_by_key(self, f: F) -> OptionItem>
1.15.0 · Source§fn min_by(self, compare: F) -> OptionItem>
fn min_by(self, compare: F) -> OptionItem>
1.0.0 · Source§fn rev(self) -> Rev ⓘwhere
Self: Sized + DoubleEndedIterator,
fn rev(self) -> Rev ⓘwhere
Self: Sized + DoubleEndedIterator,
1.0.0 · Source§fn unzip(self) -> (FromA, FromB)
fn unzip(self) -> (FromA, FromB)
1.36.0 · Source§fn copied<'a, T>(self) -> Copied ⓘ
fn copied<'a, T>(self) -> Copied ⓘ
Source§fn array_chunksusize>(self) -> ArrayChunks ⓘwhere
Self: Sized,
fn array_chunksusize>(self) -> ArrayChunks ⓘwhere
Self: Sized,
iter_array_chunks
#100450)N
elements of the iterator at a time. Read more1.11.0 · Source§fn product
(self) -> P
fn product
(self) -> P
1.5.0 · Source§fn cmp(self, other: I) -> Orderingwhere
I: IntoIterator- Item>,
Self::Item: Ord,
Self: Sized,
fn cmp(self, other: I) -> Orderingwhere
I: IntoIterator- Item>,
Self::Item: Ord,
Self: Sized,
Source§fn cmp_by(self, other: I, cmp: F) -> Ordering
fn cmp_by(self, other: I, cmp: F) -> Ordering
iter_order_by
#64295)Iterator
with those
of another with respect to the specified comparison function. Read more1.5.0 · Source§fn partial_cmp(self, other: I) -> Option<Ordering>
fn partial_cmp(self, other: I) -> Option<Ordering>
PartialOrd
elements of
this Iterator
with those of another. The comparison works like short-circuit
evaluation, returning a result without comparing the remaining elements.
As soon as an order can be determined, the evaluation stops and a result is returned. Read moreSource§fn partial_cmp_by(self, other: I, partial_cmp: F) -> Option<Ordering>
fn partial_cmp_by(self, other: I, partial_cmp: F) -> Option<Ordering>
iter_order_by
#64295)Iterator
with those
of another with respect to the specified comparison function. Read moreSource§fn eq_by(self, other: I, eq: F) -> bool
fn eq_by(self, other: I, eq: F) -> bool
iter_order_by
#64295)1.5.0 · Source§fn lt(self, other: I) -> bool
fn lt(self, other: I) -> bool
Iterator
are lexicographically
less than those of another. Read more1.5.0 · Source§fn le(self, other: I) -> bool
fn le(self, other: I) -> bool
Iterator
are lexicographically
less or equal to those of another. Read more1.5.0 · Source§fn gt(self, other: I) -> bool
fn gt(self, other: I) -> bool
Iterator
are lexicographically
greater than those of another. Read more1.5.0 · Source§fn ge(self, other: I) -> bool
fn ge(self, other: I) -> bool
Iterator
are lexicographically
greater than or equal to those of another. Read more