pub unsafe fn optional_cstr_to_str(ptr: *const c_char) -> Option<&'static str>
Expand description
Convert a C string pointer into an Option<&str>
.
§Safety
- Assumes
ptr
is a valid C string pointer or NULL. - The returned slice is only valid while the original C string remains allocated.
- Caller must ensure the C string outlives any usage of the returned slice.
The actual lifetime is tied to the C string’s allocation lifetime. This is acceptable because this function is only used for immediate consumption within FFI call boundaries where the C string remains valid.
This function is designed for immediate consumption within FFI calls. Do not store the returned slice for use beyond the current function scope.
§Panics
Panics if ptr
is not null but contains invalid UTF-8.