std-function
decode_utf16 — inspect invalid code units
Decode incrementally and handle invalid surrogates per item instead of rejecting an entire buffer. Expected stdout (not executed): A bad D800 B Common mistake: Assuming the iterator yields plain char values.
Formal Syntax & Structure
rust syntaxrust
char::decode_utf16(units)Working Example
Example Snippetrust
fn main() { for item in char::decode_utf16([0x41, 0xD800, 0x42]) { match item { Ok(c) => println!("{c}"), Err(e) => println!("bad {:X}", e.unpaired_surrogate()) } }}