-
How do I convert the field
pub name: [::std::os::raw::c_char; 256usize],
My goal is to format! it. I've already tried "{}" and "{:?}"
How do I convert the field
pub name: [::std::os::raw::c_char; 256usize],
My goal is to format! it. I've already tried "{}" and "{:?}"
You can of course replace println!
by format!
There are two different interpretations of [c_char; 256]
here:
An array of bytes. You thus wish to print it as an array ... of bytes, e.g., [0x42, 0x18, 0x0, ... ]
.
In that case you need to implement the logic format yourself, with a new type.
A C String with a capacity (max len) of 256. In which case, as @DanielKeep pointed out, you can use CStr
to Debug::fmt
it. This is what I would do. Sadly it requires (carefully) using unsafe
to get a copy-only-if-needed-to-append-a-null-byte-without-redundant-scans implementation, with the annoying part of CStr
API using u8
instead of c_char
s.