Caja
Caja is a simple rust library that allows for the creation of fixed sized arrays of a size unknown at compile time. It is basically Box<[T;n]> but allowing the n to be non constant value.
It implements some simple utilities like mutable and non-mutable iterators, indexing, cloning, and the like
Example
extern crate caja;
use caja::Caja;
#[allow(unused_mut)]
pub fn main() {
let bool_caja = Caja::<bool>::new(6, true);
print!("{}\n", bool_caja);
let int_caja = unsafe { Caja::<u32>::new_zeroed(47) };
print!("{:?}\n", int_caja);
assert_eq!(int_caja[33], 0);
let mut some_size_that_changes = 88usize;
let mut float_caja = unsafe { Caja::<f32>::new_uninitialized(some_size_that_changes) };
print!("{}\n", float_caja);
let mut angle: f32 = 0.0;
for i in &mut float_caja {
*i = angle.sin();
angle += 0.1;
}
for i in &float_caja {
println!("{i}");
}
let slice: &[f32] = float_caja.as_slice();
_ = slice;
let ptr: *mut f32 = float_caja.as_mut_ptr();
_ = ptr;
}