Have you wanted to be able to initialize a fixed array in Rust by calling a function to create each element? Now you can!
```rust use init_with::InitWith;
let myarray = { let mut seed = Vec::new(); let mut nextval = 0;
<[Vec<u32>; 3]>::init_with(|| {
seed.push(next_val);
next_val += 1;
seed.clone()
})
};
asserteq!(myarray, [vec![0], vec![0, 1], vec![0, 1, 2]]); ```
This crate lets you initialize the array elements in a functional manner while hiding the unsafe code that's needed to do so.
To import this crate, put the following into your Cargo.toml:
toml
[dependencies]
init_with = "0.1.0"
...and the following in your crate root:
rust
extern crate init_with;