by tveita · 11y ago · 0 comments
In this small example we lost a lot of the safety, but for a larger library I'm hoping you could still keep most of the safety of Rust and just expose a smaller subsection of "unsafe" code.
Rust is freeing the string when the function ends, since to_ptr doesn't extended its lifetime.
C seems to be getting freed memory.
AFAIK the right way is to use mem::forget to "leak" memory when giving it to C, and later have C free it by calling a Rust function that casts it back to the original type.