Crates.io | init_trait |
lib.rs | init_trait |
version | 0.2.0 |
source | src |
created_at | 2020-07-28 22:28:10.193329 |
updated_at | 2020-08-21 21:04:58.827283 |
description | A small helper trait to simplify the initialisation of 'indexable' data structures |
homepage | https://github.com/LukeMiles49/init-trait-rs |
repository | https://github.com/LukeMiles49/init-trait-rs |
max_upload_size | |
id | 270678 |
size | 11,879 |
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"