#![no_std]
#[macro_export]
macro_rules! array {
(fill=$fill:expr; $width:expr)=>{
[$fill; $width]
};
($($inits:expr),*; fill=$fill:expr; $width:expr)=>{
const {
let mut array = [$fill; $width];
let mut index: isize = -1;
$({
index += 1;
array[index as usize] = $inits;
})*
array
}
};
}
#[cfg(test)]
mod tests {
#[test]
fn empty() {
const A: [i32; 0] = array![fill=3; 0];
assert_eq!(A, []);
}
#[test]
fn fill() {
const A: [i32; 4] = array![fill=3; 4];
assert_eq!(A, [3, 3, 3, 3]);
}
#[test]
fn init_fill() {
const A: [i32; 4] = array![2; fill=3; 4];
assert_eq!(A, [2, 3, 3, 3]);
}
#[test]
fn multi_init_fill() {
const A: [i32; 10] = array![1, 2, 3; fill=10; 10];
assert_eq!(A, [1, 2, 3, 10, 10, 10, 10, 10, 10, 10]);
}
#[test]
fn fill_unused() {
const A: [i32; 3] = array![1, 2, 3; fill=10; 3];
assert_eq!(A, [1, 2, 3]);
}
#[test]
fn strs() {
const A: [&'static str; 5] = array!["hello", "world"; fill=""; 5];
assert_eq!(A, ["hello", "world", "", "", ""]);
}
}