pub fn convert_utf16_to_utf8_partial(
    src: &[u16],
    dst: &mut [u8]
) -> (usize, usize)
Expand description

Converts potentially-invalid UTF-16 to valid UTF-8 with errors replaced with the REPLACEMENT CHARACTER with potentially insufficient output space.

Returns the number of code units read and the number of bytes written.

Not all code units are read if there isn’t enough output space.

Note that this method isn’t designed for general streamability but for not allocating memory for the worst case up front. Specifically, if the input starts with or ends with an unpaired surrogate, those are replaced with the REPLACEMENT CHARACTER.

Safety

Note that this function may write garbage beyond the number of bytes indicated by the return value, so using a &mut str interpreted as &mut [u8] as the destination is not safe. If you want to convert into a &mut str, use convert_utf16_to_str() instead of this function.