pub struct CStrPtr(/* private fields */);Expand description
A pointer to a NUL-terminated narrow string (char*), possibly null.
Reading it is unsafe: the pointer comes from the target and can’t be
checked. A null pointer reads as an empty string.
§Examples
use imping_runtime::CStrPtr;
let greeting = CStrPtr::from(c"hello");
// SAFETY: `greeting` points to a static, NUL-terminated string.
assert_eq!(unsafe { greeting.to_string_lossy() }, "hello");
assert_eq!(unsafe { CStrPtr::null().to_string_lossy() }, "");Implementations§
Source§impl CStrPtr
impl CStrPtr
Sourcepub const fn as_mut_ptr(self) -> *mut c_char
pub const fn as_mut_ptr(self) -> *mut c_char
Returns the raw pointer as *mut, for functions that write through it.
Sourcepub unsafe fn to_bytes<'a>(self) -> &'a [u8] ⓘ
pub unsafe fn to_bytes<'a>(self) -> &'a [u8] ⓘ
Returns the string’s bytes without the terminating NUL, or an empty slice if the pointer is null.
As with CStr::from_ptr, the caller chooses the lifetime 'a.
§Safety
A non-null pointer must point to a NUL-terminated string that stays
valid and unchanged for 'a.
Sourcepub unsafe fn to_string_lossy<'a>(self) -> Cow<'a, str>
pub unsafe fn to_string_lossy<'a>(self) -> Cow<'a, str>
Returns the string as UTF-8, with invalid sequences replaced by �.
§Safety
A non-null pointer must point to a NUL-terminated string that stays
valid and unchanged for 'a.
Sourcepub unsafe fn to_string_ansi(self) -> String
pub unsafe fn to_string_ansi(self) -> String
Decodes the string with the system’s ANSI code page, as Windows “A” functions do.
On other platforms, the same as to_string_lossy.
§Safety
A non-null pointer must point to a NUL-terminated string that stays valid and unchanged during the call.