cstr_as_str

Function cstr_as_str 

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

Convert a C string pointer into a borrowed string slice.

§Safety

  • Assumes ptr is a valid, null-terminated UTF-8 C string pointer.
  • The returned &str borrows the underlying allocation; callers must ensure the C buffer outlives every use of the string slice.

§Panics

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