cbindgen
cbindgen copied to clipboard
Handling str and String
Is it possible to handle str and String in a way that they are automatically converted to Cstr and Cstring?
cbindgen does not generate any new rust code. It also does not generate any C function definitions. It merely generates a header file listing exposed functions and types. This means that it can not generate wrapper code doing these conversions.
Also notice that str cannot be converted to cstr failsave and without allocation (as str may contain internal 0s and has no 0 terminator). The inverse way (cstr->str) is also dependend on whether the cstr contains valid Unicode.
What you would need is a more advanced binding generator that also generates the wrapper code on the Rust side.
^ is correct.