1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#![cfg(all(feature = "std", feature = "c-types"))]
use std::os::raw::c_char;
use std::ffi::CStr;
use std::str::Utf8Error;
#[cfg(any(feature = "panic-if-null", debug_assertions))]
use super::panic_if_null;
#[must_use]
#[inline]
pub unsafe fn ref_str<'a>(string: *const c_char) -> Result<&'a str, Utf8Error> {
#[cfg(any(feature = "panic-if-null", debug_assertions))]
panic_if_null(string);
let string = CStr::from_ptr(string);
return string.to_str();
}