#array #heap-allocated #heap #size #fixed-size #compile-time #unknown

caja

添加了Caja结构体,它基本上是Box<[T;n]>,但n可以在编译时未知

4个版本

0.2.1 2024年2月9日
0.2.0 2024年2月9日
0.1.1 2024年1月30日
0.1.0 2024年1月30日

274内存管理

每月下载 30

GPL-3.0-or-later

16KB
131

caja


caja是一个简单的Rust库,允许创建编译时大小未知的固定大小数组。它基本上是 Box<[T;n]>,但允许 n 为非常量值。

示例


extern crate caja;

use caja::Caja;



pub fn main() {

    // Creates a heap allocated array of size 108 with the default value 0xEE

    let caj = Caja::<u16>::new(108, 0xEE).unwrap();

    // it is also possible to use new_zeroed and new_uninitialized



    // Caja implements Display and Debug, as long as T does so too.

    println!("{}", caj);

    

    // Caja implements Index and IndexMut, so it is possible to access it as any normal array.

    println!("{}", caj[77]);



    //  And you can also access the underlying pointer inside of Caja

    println!("{:p}", caj.as_mut_ptr());

}

无运行时依赖