A small helper trait to simplify the initialisation of 'indexable' data structures.
use init_trait::Init;
struct House { number: usize }
// [T; N]: Init<T, usize>
let road = <[House; 3]>::init(|i| House { number: i + 1 });
assert_eq!(road[0].number, 1);
assert_eq!(road[1].number, 2);
assert_eq!(road[2].number, 3);
To use this, add it as a dependency to your Cargo.toml:
[dependencies]
init_trait = "0.2.0"