INNER CODE UNIT · Rust
alloc
binius-zk/binius64 · crates/compute/src/lib.rs:50
fn alloc<T: Send>(&self, capacity: usize) -> Self::Vec<T>;
}
/// Collects a parallel iterator into a buffer drawn from an [`Allocator`].
///
/// The allocator's counterpart to [`IndexedParallelIterator::collect_into_vec`], which targets a
/// `&mut Vec` that a generic buffer is not. The buffer is sized to the iterator's length, and its
/// uninitialized capacity is written in parallel rather than zero-filled first.
pub trait CollectIntoAllocVec: IndexedParallelIterator {
/// Allocates a buffer holding one element per item and fills it with the iterator's items.
///
/// ```
/// use binius_compute::{CollectIntoAllocVec, GlobalAllocator};
/// use rayon::prelude::*;
///
/// let squares = (0..8usize).into_par_iter().map(|i| i * i);
/// let buffer = squares.collect_into_alloc_vec(&GlobalAllocator);
/// assert_eq!(&*buffer, &[0, 1, 4, 9, 16, 25, 36, 49]);