在下面的 Rust 代码中,我无法将字节数组转换为 GenericArray。编译器告诉我给一个类型“字节”,如 generic_array::GenericArray<u8, N>,但我不知道使用什么作为“N”。
我发现 N 必须是 ArrayLength 类型,并且我被困在这里,因为我没有看到要传递的大小的链接。
fn main() {
use aes::block_cipher_trait::generic_array::GenericArray;
let phrase = "Le Rust tu comprendras jeune padawan !";
println!("my phrase {:?}", &phrase);
let b = phrase.as_bytes();
println!("my bytes {:?} len : {}", &b, b.len());
let bytes = GenericArray::clone_from_slice(&b[0..16]);
println!("my bytes {:?}", &bytes);
}
Run Code Online (Sandbox Code Playgroud) 如何动态分配内存空间并获取指向 Zig 中结构列表的指针。
就像在 C 中一样:
struct Foo* my_array_of_foo = (struct Foo*) malloc(10*sizeof(Foo));
Run Code Online (Sandbox Code Playgroud)