pub struct WStrPtr(/* private fields */);Expand description
A pointer to a NUL-terminated UTF-16 string (wchar_t* on Windows),
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::WString;
let title = WString::from("Héllo");
// SAFETY: `title` is alive and NUL-terminated.
assert_eq!(unsafe { title.as_ptr().to_string_lossy() }, "Héllo");Implementations§
Source§impl WStrPtr
impl WStrPtr
Sourcepub const fn as_mut_ptr(self) -> *mut u16
pub const fn as_mut_ptr(self) -> *mut u16
Returns the raw pointer as *mut, for functions that write through it.
Sourcepub unsafe fn to_wide<'a>(self) -> &'a [u16]
pub unsafe fn to_wide<'a>(self) -> &'a [u16]
Returns the string’s UTF-16 code units 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 UTF-16 string that
stays valid and unchanged for 'a.
Sourcepub unsafe fn to_string_lossy(self) -> String
pub unsafe fn to_string_lossy(self) -> String
Returns the string as UTF-8, with unpaired surrogates replaced by �.
§Safety
A non-null pointer must point to a NUL-terminated UTF-16 string that stays valid and unchanged during the call.
Trait Implementations§
impl Copy for WStrPtr
impl Eq for WStrPtr
impl Plain for WStrPtr
impl StructuralPartialEq for WStrPtr
Auto Trait Implementations§
impl !Send for WStrPtr
impl !Sync for WStrPtr
impl Freeze for WStrPtr
impl RefUnwindSafe for WStrPtr
impl Unpin for WStrPtr
impl UnsafeUnpin for WStrPtr
impl UnwindSafe for WStrPtr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more