I'm trying to interact with a low-level C API using Rust. It requires calling to get the size of an array, then calling again with an allocated array of structs to match that size, function looks like
getVals(pNumItems: *mut usize,
pItems: *mut)
per the API usage, I'm doing this:
let mut numItems: usize = 0;
getVals(&numItems,
ptr::null_mut());
// Now we know count, so make an array of MyInfo structs and call again:
let itemInfo: Vec<MyInfo> = Vec::with_capacity(numItems);
getVals(&numItems, itemInfo.as_mut_ptr());
But the first call can't compile because I get error message:
mismatched types expected raw pointer
*mut u32found reference&usizelet mut items
I'm unclear what the difference is here. I tried casting it to *mut u32 but that complains about it being unsafe. This whole block of code is being done inside
unsafe{}
So, I'm thinking I'm not doing this correctly. Is there a better way to do this?
My vector creation and usage doesn't have compile-time errors, but I'm not sure if that is the expected way to do this?
usizeis notu32, so I can't coerce reference to the former to pointer to the latter".