7 stable releases
1.3.1 | Jan 5, 2025 |
---|---|
1.3.0 | Oct 16, 2023 |
1.2.0 | Sep 30, 2023 |
#123 in Memory management
1,560 downloads per month
10KB
112 lines
Safe way to allocate and initialize nested arrays directly on the heap inside a Box
.
Usage
In order to initialize a Boxed nested-array, simply call the boxarray
function and give it the value (here v
) to initialize with:
let v = 7.0;
let a: Box<[[[f64; 3]; 2]; 4]> = boxarray::boxarray(v);
The initialization can also be done with a function that takes the coordinates in nested tuples as arguments by using boxarray_
instead:
let f = |((((), i), j), k)| (i+j*k) as usize;
let a: Box<[[[usize; 3]; 2]; 4]> = boxarray::boxarray_(f);
boxarray
Safe way to allocate and initialize nested arrays directly on the heap in Rust.
Usage
To use boxarray
in your Rust project, simply add it as a dependency in your Cargo.toml
:
[dependencies]
boxarray = "1.3.1"
Then import and use it in your project:
use boxarray::boxarray;
use boxarray::boxarray_;
fn main() {
let v = 7.0;
let a: Box<[[[f64; 3]; 2]; 4]> = boxarray(v);
println!("{a:?}");
let f = |((((), i), j), k)| (i+j*k) as usize;
let a: Box<[[[usize; 3]; 2]; 4]> = boxarray_(f);
println!("{a:?}");
}