[−][src]Macro c_macros::to_raw_c_string
to_raw_c_string!() { /* proc-macro */ }
Convert an encoded string to a *mut c_char
allocated in the system heap.
Examples
#![feature(proc_macro_hygiene, new_uninit, type_ascription)] use c_macros::to_raw_c_string; use std::ffi::CString; use std::os::raw::c_char; #[link(name = "my_library.h")] extern "C" { fn mutate_foo(foo: *mut c_char); } let foo = to_raw_c_string!("Hello world!\n"); unsafe { mutate_foo(foo); } let _ = unsafe { CString::from_raw(foo) }; // properly drop the allocated c string before it goes out of scope