pub trait IterCollectArray: Iterator {
// Provided method
fn collect_array<const N: usize>(self) -> [Self::Item; N]
where Self: Sized { ... }
}Available on crate feature
collect_array only.Expand description
An extension trait that provides the collect_array method for iterators.
Provided Methods§
Sourcefn collect_array<const N: usize>(self) -> [Self::Item; N]where
Self: Sized,
fn collect_array<const N: usize>(self) -> [Self::Item; N]where
Self: Sized,
Consumes the entire iterator collecting it into an array.
§Panics
If the iterator contains too little or too many elements to fit in the
array. If you want to handle these cases, use next_chunk which
supports returning the remainder and doesn’t panic if there are too many
elements.
§Examples
Basic usage:
use itermore::IterCollectArray;
let mut iter = "a,b,c".split(",");
let arr: [_; 3] = iter.collect_array();
assert_eq!(arr, ["a", "b", "c"]);