[−][src]Trait init_trait::Init
Types which can be initialised by applying a function to each 'index' of the type.
Required methods
fn init_with<F: FnMut(I) -> T>(value: V, elem: F) -> Self
Initialise an instance of this type using value
by applying elem
to each 'index' of the type.
Examples
Constructing a Vec containing the values 0 to 4:
use init_trait::Init; let vec = Vec::<usize>::init_with(5, |i| i); assert_eq!(vec, vec![0, 1, 2, 3, 4]);
Provided methods
fn init<F: FnMut(I) -> T>(elem: F) -> Self where
V: TypeEquals<()>,
V: TypeEquals<()>,
Initialise an instance of this type by applying elem
to each 'index' of the type.
This is syntax sugar for init_with((), elem)
.
Examples
Constructing an array containing the values 0 to 4:
use init_trait::Init; let arr = <[usize; 5]>::init(|i| i); assert_eq!(arr, [0, 1, 2, 3, 4]);