Macro grid

Source
macro_rules! grid {
    ($([$([$([$([$([$($x:expr),* $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?) => { ... };
    ($([$([$([$([$($x:expr),* $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?) => { ... };
    ($([$([$([$($x:expr),* $(,)?]),+ $(,)?]),+ $(,)?]),+ $(,)?) => { ... };
    ($([$([$($x:expr),* $(,)?]),+ $(,)?]),+ $(,)?) => { ... };
    ($([$($x:expr),* $(,)?]),+ $(,)?) => { ... };
    ($($x:expr),* $(,)?) => { ... };
    ([[[[[$elem:expr; $i:expr]; $j:expr]; $k:expr]; $l:expr]; $m:expr]; $n:expr) => { ... };
    ([[[[$elem:expr; $i:expr]; $j:expr]; $k:expr]; $l:expr]; $m:expr) => { ... };
    ([[[$elem:expr; $i:expr]; $j:expr]; $k:expr]; $l:expr) => { ... };
    ([[$elem:expr; $i:expr]; $j:expr]; $k:expr) => { ... };
    ([$elem:expr; $i:expr]; $j:expr) => { ... };
    ($elem:expr; $i:expr) => { ... };
}
Expand description

Creates a dense multidimensional array containing the arguments.

This macro is used to create an array, similar to the vec! macro for vectors. There are two forms of this macro:

  • Create an array containing a given list of elements:
use mdarray::{grid, Grid};

let a = grid![[1, 2], [3, 4]];

assert_eq!(a, Grid::from([[1, 2], [3, 4]]));
  • Create an array from a given element and shape by cloning the element:
use mdarray::{grid, Grid};

let a = grid![[1; 2]; 3];

assert_eq!(a, Grid::from_elem([2, 3], 1));

In the second form, like for vectors the shape does not have to be constant.