How to publish a constant string in the Rust FFI?
I want to have a Rust library expose a const char * static string to C, to be compatible with an existing interface (specifically librsync ). That is, the C header file has extern char const *my_string; In C, the library would simply have char const *my_string = "hi"; In Rust I've tried something like pub static my_string: *const libc::c_char = unsafe { "hi\0" as *const libc::c_char }; but this complains error: casting `&'static str` as `*const i8` is invalid It seems like I can't use CString etc because they won't be a compile-time constant expression. This gets a little weird, so bear with