pub struct Utf16Error { /* private fields */ }
Expand description
Error for invalid UTF-16 encoded bytes.
Implementations§
Source§impl Utf16Error
impl Utf16Error
Sourcepub fn valid_up_to(&self) -> usize
pub fn valid_up_to(&self) -> usize
Returns the index in given bytes up to which valid UTF-16 was verified.
Sourcepub fn error_len(&self) -> Option<usize>
pub fn error_len(&self) -> Option<usize>
Return the length of the error if it is recoverable.
-
None
: the end of the input was reached unexpectedly.Utf16Error::valid_up_to
is 1 to 3 bytes from the end of the input. If a byte stream such as a file or a network socket is being decoded incrementally, this could still be a valid char whose byte sequence is spanning multiple chunks. -
Some(len)
: an unexpected byte was encountered. The length provided is that of the invalid byte sequence that starts at the index given byUtf16Error::valid_up_to
. Decoding should resume after that sequence (after inserting aU+FFFD REPLACEMENT CHARACTER
) in case of lossy decoding. In fact for UTF-16 thelen
reported here will always be exactly 2 since this never looks ahead to see if the bytes following the error sequence are valid as well as otherwise you would not know how many replacement characters to insert when writing a lossy decoder.
The semantics of this API are compatible with the semantics of
Utf8Error
.
Trait Implementations§
Source§impl Clone for Utf16Error
impl Clone for Utf16Error
Source§fn clone(&self) -> Utf16Error
fn clone(&self) -> Utf16Error
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more