partial-array
- potentially partial-filled arrays for #![no_std]
This crate provides a central new data type, similar to an [array]: the [PartialArray<N>
].
It is equivalent to an array, but the number of entries might be anywhere from 0
to N
.
While this has similarities to a Vec<T>
keep in mind, that a [PartialArray
] does not grow its memory: it always takes up the memory for the fully array (with some additional counter) and it cannot ever hold more than N
elements.
This means that its memory is fully static and on the stack, making it usable from #![no_std]
crates.
Usages
This new data type is most likely to be used for collecting iterators into arrays, when then length is not known, but has an upper bound, e.g.:
use PartialArray;
/// Take the first 10 elements of an iterator, that match the condition.
///
/// This can return less than 10 elements if the iterator has fewer than 10
/// items or there are less than 10 matching elements.