[][src]Function ffi_support::rust_string_to_c

pub fn rust_string_to_c(rust_string: impl Into<String>) -> *mut c_char

Convert a rust string into a NUL-terminated utf-8 string suitable for passing to C, or to things ABI-compatible with C.

Important: This string must eventually be freed. You may either do that using the [destroy_c_string] method (or, if you must, by dropping the underlying [std::ffi::CString] after recovering it via [std::ffi::CString::from_raw]).

It's common to want to allow the consumer (e.g. on the "C" side of the FFI) to be allowed to free this memory, and the macro [define_string_destructor!] may be used to do so.

Panics

This function may panic if the argument has an interior null byte. This is fairly rare, but is possible in theory.