pub fn boxarray<E: Copy, L: CUList, T: Arrays<E, L>>(e: E) -> Box<T>Expand description
The boxarray function allow to allocate and initialize nested arrays directly on the heap inside a Box.
Examples
Single array.
fn signle_array() {
let a: Box<[u32; 10]> = boxarray::boxarray(1);
assert_eq!(*a, [1u32; 10]);
}Nested array.
fn nested_array() {
let a: Box<[[[f64; 10]; 2]; 4]> = boxarray::boxarray(7.0);
assert_eq!(*a, [[[7f64; 10]; 2]; 4]);
}If the type of the value to initialize with does not correspond, a compiler will be raised.
ⓘ
fn nested_array_wrong_type() {
let a: Box<[[[f64; 10]; 2]; 4]> = boxarray::boxarray(7.0f32);
assert_eq!(*a, [[[7f64; 10]; 2]; 4]);
}If the type to initialize is not only composed of nested arrays, a compiler will be raised.
ⓘ
fn nested_array_wrong_type() {
let a: Box<[[([f64; 10], [f64; 10]); 2]; 4]> = boxarray::boxarray(7.0);
assert_eq!(*a, [[[7f64; 10]; 2]; 4]);
}