Function core::array::drain::drain_array_with
source · pub(crate) fn drain_array_with<T, R, const N: usize>(
array: [T; N],
func: impl for<'a> FnOnce(Drain<'a, T>) -> R
) -> R
Expand description
A situationally-optimized version of array.into_iter().for_each(func)
.
crate::array::IntoIter
s are great when you need an owned iterator, but
storing the entire array inside the iterator like that can sometimes
pessimize code. Notable, it can be more bytes than you really want to move
around, and because the array accesses index into it SRoA has a harder time
optimizing away the type than it does iterators that just hold a couple pointers.
Thus this function exists, which gives a way to get moved access to the elements of an array using a small iterator – no bigger than a slice iterator.
The function-taking-a-closure structure makes it safe, as it keeps callers from looking at already-dropped elements.