generic_array

Macro arr

Source
macro_rules! arr {
    ($($x:expr),* $(,)*) => { ... };
    ($x:expr; $N:ty) => { ... };
    ($x:expr; $n:expr) => { ... };
}
Expand description

Macro allowing for easy construction of Generic Arrays.

Type-inference works similarly to vec![]

arr! can be used in const expressions.

Example:

use generic_array::typenum::U6;

let test = arr![1, 2, 3]; // implicit length
let test = arr![1; 6];    // explicit length via `Const<N>`
let test = arr![1; U6];   // explicit length via typenum

ยงNOTES AND LIMITATIONS

  • As of generic-array 1.0, From/from_array can be used directly for a wide range of regular arrays.
  • The [T; N: ArrayLength] and [T; usize] explicit forms are limited to Copy values. Use GenericArray::generate(|| value.clone()) for non-Copy items.
  • The [T; usize] explicit and [0, 1, 2, 3] implicit forms are limited to lengths supported by Const<U>