Skip to main content

Wtf16Str

Type Alias Wtf16Str 

Source
pub type Wtf16Str = WtfStr<Wtf16>;
Expand description

A WtfStr whose storage is WTF-16 (u16 code units).

Aliased Type§

pub struct Wtf16Str { /* private fields */ }

Implementations§

Source§

impl Wtf16Str

Source

pub fn to_os_string(&self) -> OsString

Decode the content into an owned OsString, losslessly.

The OsStringExt::from_wide bridge: unpaired surrogates are preserved.

Source

pub fn encode_wide(&self) -> impl Iterator<Item = u16> + '_

Iterate the content as wide code units, zero-copy: the OsStrExt::encode_wide analog over our own slice.

Source§

impl Wtf16Str

Source

pub fn as_ptr(&self) -> *const u16

A pointer to the content code units, for counted FFI paired with len.

The pointer is not guaranteed to be NUL-terminated (a borrowed slice carries no terminator); use it only with the matching unit count. It is valid while self is borrowed and unmodified. For a terminated LPCWSTR, start from an owned Wtf16String and use Wtf16String::as_terminated_ptr.

Examples found in repository?
examples/win32_round_trip.rs (line 147)
142    fn ordinal(a: &Wtf16Str, b: &Wtf16Str) -> i32 {
143        // SAFETY: each pointer is valid for exactly its own `len()` units while
144        // borrowed, which is the contract `CompareStringOrdinal` expects.
145        unsafe {
146            CompareStringOrdinal(
147                a.as_ptr(),
148                a.len() as i32,
149                b.as_ptr(),
150                b.len() as i32,
151                0, // case-sensitive
152            )
153        }
154    }