How to expose a Rust `Vec<T>` to FFI?
问题 I'm trying to construct a pair of elements: array: *mut T array_len: usize array is intended to own the data However, Box::into_raw will return *mut [T] . I cannot find any info on converting raw pointers to slices. What is its layout in memory? How do I use it from C? Should I convert to *mut T ? If so, how? 回答1: If you just want some C function to mutably borrow the Vec , you can do it like this: extern "C" { fn some_c_function(ptr: *mut i32, len: ffi::size_t); } fn safe_wrapper(a: &mut