My FFI binding returns a struct with fixed-size c_char arrays, and I would like to turn those into std::ffi::CString or std::String.
It looks like the CString::new function coerces the pointer to a vector.
use std::ffi::CString;
use std::os::raw::c_char;
#[repr(C)]
pub struct FFIStruct {
pub Id: [::std::os::raw::c_char; 256usize],
pub Description: [::std::os::raw::c_char; 256usize],
}
fn get_struct() -> Option<FFIStruct> {
println!("cheating");
None
}
pub fn main() {
match get_struct() {
Some(thing) =>
println!("Got id:{}",CString::new(thing.Id.as_ptr())),
None => (),
}
}
Here is the Rust Playground link.