I've written a function in C with this signature:
write_stuff(char **pages, uint32 page_count);
pages
will be an array of 128 elements, with each element either NULL or pointing to a char array of 8192 bytes. So, an array of arrays with fixed, known sizes.
I need to populate the arrays in Rust and pass them to the C function. When I generate a Rust signature using bindgen, it produces this:
extern "C" {
pub fn write_stuff(pages: *mut *mut ::std::os::raw::c_char, page_count: u32,);
}
Now, how do I declare a variable in Rust that I can populate and pass to this function?
I tried this:
let mut pages = [Option <[u8; 8192]>; 128];
but it doesn't compile.
This does compile:
type MyPage = Option<[u8; 8192]>;
let myarray: [MyPage; 128] = [None; 128];
but I'm not clear on whether it would store the data in the right format, or how to cast it appropriately:
let pages: *mut *mut ::std::os::raw::c_char = myarray.as_mut_ptr() as // what goes here?;