Skip to content

A small helper trait to simplify the initialisation of 'indexable' data structures

Notifications You must be signed in to change notification settings

LukeMiles49/init-trait-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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"

About

A small helper trait to simplify the initialisation of 'indexable' data structures

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages