Struct astral_string::Utf8Error
pub struct Utf8Error { /* private fields */ }
Expand description
Implementations
impl Utf8Error
impl Utf8Error
pub fn valid_up_to(&self) -> usize
pub fn valid_up_to(&self) -> usize
Returns the index in the given string up to which valid UTF-8 was verified.
It is the maximum index such that from_utf8(&input[..index])
would return Ok(_)
.
Example
use astral::string::Name;
// some invalid bytes, in a vector
let sparkle_heart = &[0, 159, 146, 150];
// Name::from_utf8 returns a Utf8Error
let error = Name::from_utf8(sparkle_heart, &string_subsystem).unwrap_err();
// the second byte is invalid here
assert_eq!(1, error.valid_up_to());
pub fn error_len(&self) -> Option<usize>
pub fn error_len(&self) -> Option<usize>
Provide more information about the failure:
-
None
: the end of the input was reached unexpectedly.self.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 be a validchar
whose UTF-8 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 byvalid_up_to()
. Decoding should resume after that sequence (after inserting aU+FFFD REPLACEMENT CHARACTER
) in case of lossy decoding.