pub unsafe fn stackalloc_from_iter_trusted<I, T, U, F>(
    iter: I,
    callback: F
) -> U where
    F: FnOnce(&mut [T]) -> U,
    I: IntoIterator<Item = T>, 
Expand description

Collect an iterator into a stack allocated buffer, call callback with this buffer, and then drop and deallocate the buffer.

Safety

While the slice passed to callback is guaranteed to be safe to use, regardless of if the iterator fills (or tries to overfill) it, this function is still marked as unsafe because it trusts the iterator I reports an accurate length with its size_hint(). It is recommended to instead use stackalloc_with_iter() specifying a strict upper bound on the buffer’s size, or stackalloc_from_iter_exact() for ExactSizeIterators, as this function may allocate far more, or far less (even 0) memory needed to hold all the iterator’s elements; therefore this function will very easily not work properly and/or cause stack overflow if used carelessly.

If the standard library’s std::iter::TrustedLen trait becomes stablised, this function will be changed to require that as a bound on I and this function will no longer be unsafe.

Size

The size allocated for the buffer will be the upper bound of the iterator’s size_hint() if one exists. If not, then the size allocated will be the lower bound of size_hint(). This can potentially result in only some of the iterator being present in the buffer, or the buffer allocated being much larger than the iterator itself. If this iterator does not have a good size_hint() for this purpose, use stackalloc_with_iter(), or stackalloc_from_iter_exact() if the iterator has an exact size.