arr_rs/macros/
flat.rs

1/// Create a flat array
2///
3/// # Examples
4///
5/// ```
6/// use arr_rs::prelude::*;
7///
8/// let arr = array_flat!(i32, 1, 2, 3, 4, 5, 6, 7, 8);
9/// assert_eq!(vec![8], arr.get_shape().unwrap());
10/// let arr = array_flat!(f64, 1., 2., 3., 4., 5., 6., 7., 8.);
11/// assert_eq!(vec![8], arr.get_shape().unwrap());
12/// ```
13#[macro_export]
14macro_rules! array_flat {
15    ($([$($nested:expr),*]),* $(,)*) => {{
16        compile_error!("array_flat! only accepts a flat list of elements");
17    }};
18    ($tt:ty, $([$($nested:expr),*]),* $(,)*) => {{
19        compile_error!("array_flat! only accepts a flat list of elements");
20    }};
21    (Tuple2<$t1:ty, $t2:ty>, $($x:expr),* $(,)*) => {{
22        array_tuple!(Tuple2<$t1, $t2>, format!("{:?}", vec![$(vec![$x],)*]))
23    }};
24    (Tuple3<$t1:ty, $t2:ty, $t3:ty>, $($x:expr),* $(,)*) => {{
25        array_tuple!(Tuple3<$t1, $t2, $t3>, format!("{:?}", vec![$(vec![$x],)*]))
26    }};
27    (List<$tt:ty>, $($x:expr),* $(,)*) => {{
28        array_list!(List<$tt>, format!("{:?}", vec![$(vec![$x],)*]))
29    }};
30    (char, $($x:expr),* $(,)*) => {{
31        array_char!(format!("{:?}", vec![$(vec![$x],)*]))
32    }};
33    (String, $($x:expr),* $(,)*) => {{
34        array_string!(format!("{:?}", vec![$(vec![$x],)*]))
35    }};
36    ($tt:ty, $($x:expr),* $(,)*) => {{
37        array!($tt, vec![$($x,)*])
38    }};
39}