pub fn raw_cstr<S>(str: S) -> Result<*mut i8>Expand description
Create a constant raw C string as a *mut i8 from a Rust string reference. C Strings are cached,
and creating the same string twice will cost zero additional memory. This is useful when calling
C APIs that take a string as an argument, particularly when the string can’t be known at compile
time, although this function is also efficient in space (but not time) when a constant string
is known. For compile-time constants, you can use c_str!.
§Safety
- Do not use
String::from_raw_partsto convert the pointer back to aString. This may cause a double free because theStringwill take ownership of the pointer. UseCStr::from_ptrinstead, and convert to a string with.to_str().expect("...").to_owned()instead.