Function cstr_as_str

Source
pub unsafe fn cstr_as_str(ptr: *const c_char) -> &'static str
Expand description

Convert a C string pointer into a string slice.

§Safety

  • Assumes ptr is a valid C string pointer.
  • 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.

§Panics

Panics if ptr is null or contains invalid UTF-8.

§Note

This function is designed for immediate consumption within FFI calls. Do not store the returned slice for use beyond the current function scope.