Skip to main content

from_indices

Macro from_indices 

Source
macro_rules! from_indices {
    ($($from_indices_args:tt)*) => { ... };
}
Expand description

Creates an array by evaluating a function for each index in 0..N in const contexts.

ยงExamples

use const_tools::from_indices;

const fn powers_of_two<const N: usize>() -> [u32; N] {
    from_indices!(N, |index| 1 << index)
}

assert!(matches!(powers_of_two::<4>(), [1, 2, 4, 8]));