silk.platform.windows.wtf8.
Lossless conversion between Windows UTF-16 code units and canonical WTF-8 bytes.
When to use#
Use Wtf8.encode for raw host values and Wtf8.decodeBytes for their inverse. Lone surrogates
remain bytes. Use String.fromUtf8 separately when a caller needs valid Unicode text.
Import as Wtf8 with import silk.platform.windows.wtf8 { Wtf8 }.
Public declarations: 3.
InvalidWtf8#
pub struct InvalidWtf8A malformed or noncanonical WTF-8 byte sequence.
Implementation Debug for InvalidWtf8#
impl Debug for InvalidWtf8Operation debug#
effect fn debug(self: &Self, formatter: &mut Formatter) -> () ! WriterError ? &mut WriterWrites InvalidWtf8.
Wtf8Point#
pub struct Wtf8PointOne decoded code point, including a possible lone surrogate, and the next byte offset.
Field value#
pub value: u32The code point, from 0 through 0x10ffff, including lone surrogates.
Field end#
pub end: usizeThe byte offset immediately after the code point.
Wtf8#
pub struct Wtf8Conversion of arbitrary UTF-16 code units to canonical WTF-8 bytes, without replacement characters.
Implementation Wtf8#
impl Wtf8Associated function encode#
pub effect fn encode(units: &[u16]) -> Bytes ! OutOfMemoryError ? &mut AllocatorReturns canonical WTF-8 bytes for units. Pairs become one scalar; lone surrogates survive.
Details#
NUL is preserved. Host APIs that use NUL terminators must reject embedded NUL separately.
Errors#
OutOfMemoryErrorif the output cannot be allocated.
Associated function pointBytes#
pub fn pointBytes(bytes: &[u8], at: usize) -> Option<Wtf8Point>Decodes one canonical WTF-8 code point at at, or returns an absent option for invalid input.
Details#
An absent result also indicates the end of input. Callers start at zero and advance to end.
Overlong encodings, values above 0x10ffff, and separately encoded adjacent surrogate pairs are rejected.
Lone surrogates and NUL are accepted. This operation does not allocate.
Associated function decodeBytes#
pub effect fn decodeBytes(bytes: &[u8]) -> List<u16> ! InvalidWtf8 | OutOfMemoryError ? &mut AllocatorReturns the UTF-16 code units of canonical WTF-8 bytes, preserving lone surrogates and NUL.
Errors#
InvalidWtf8for malformed bytes or separately encoded adjacent high and low surrogates.OutOfMemoryErrorif the output cannot be allocated.
Category: Windows platform.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.