cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Handling str and String

Open aminya opened this issue 2 years ago • 1 comments

Is it possible to handle str and String in a way that they are automatically converted to Cstr and Cstring?

aminya avatar Aug 30 '21 06:08 aminya

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.

nacaclanga avatar Sep 23 '21 09:09 nacaclanga