I want to do this
// I cannot alter this function
fn a_ffi_function(buffer: &[u8; 16]) {
unsafe {
}
}
fn main() {
let buffer = [0u8; 64];
for i in 0..4 {
a_ffi_function(&buffer[i*16..(i+1)*16]);
}
}
But the compiler does not allow me to
error[E0308]: mismatched types
--> src/main.rs:10:24
|
10 | a_ffi_function(&buffer[i*16..(i+1)*16]);
| ^^^^^^^^^^^^^^^^^^^^^^^ expected array of 16 elements, found slice
|
= note: expected type `&[u8; 16]`
found type `&[u8]`
I cannot find a way to cast from &[u8]
to &[u8; 16]
. What can I do?
I don't want to copy memory. This application is time-sensitive.
I am using rustc 1.27.0-nightly (ad610bed8 2018-04-11).