init_trait

Crates.ioinit_trait
lib.rsinit_trait
version0.2.0
sourcesrc
created_at2020-07-28 22:28:10.193329
updated_at2020-08-21 21:04:58.827283
descriptionA small helper trait to simplify the initialisation of 'indexable' data structures
homepagehttps://github.com/LukeMiles49/init-trait-rs
repositoryhttps://github.com/LukeMiles49/init-trait-rs
max_upload_size
id270678
size11,879
Luke Miles (LukeMiles49)

documentation

https://docs.rs/init_trait

README

init_trait

Crate

Documentation

Repository

Changelog

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"
Commit count: 2

cargo fmt