- I get the following error:
= note: expected type `*const i8`
found type `&'static [u8; 16]`
- This is generated by trying to pass
b"00000000:83:00.0"
(a PCI bus id) to a C FFI function that expects a char*
- How do I fix this?
= note: expected type `*const i8`
found type `&'static [u8; 16]`
b"00000000:83:00.0"
(a PCI bus id) to a C FFI function that expects a char*
You will need two casts, one to *const [i8;16]
then to *const i8
.
If my initial string is NOT null termianted, but the C FFI does need it to be NULL termianted, then I actually need CString::new(...) right?
If you're ok with copying the data (you don't need a pointer to those particular bytes), yes, and you pass the result of as_ptr()
. From your use case, this is what you want this time.
If you need that memory specifically to be passed to FFI for some reason (usually &mut and C is going to modify something there) you want &Cstr
instead, and you'll have to put the nul termination first.