Function hugr_core::utils::try_collect_array

source ·
pub fn try_collect_array<const N: usize, T>(
    arr: impl IntoIterator<Item = T>,
) -> Result<[T; N], Vec<T>>
Expand description

Collect a vector into an array.

This is useful for deconstructing a vectors content.

§Example

let iter = 0..3;
let [a, b, c] = crate::utils::try_collect_array(iter)
    .unwrap_or_else(|v| panic!("Expected 3 elements, got {:?}", v));
assert_eq!(b, 1);

See also collect_array.