use core::fmt;
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
pub enum Utf8ParserError {
InvalidByte(u8),
InvalidChar(u32),
UnexpectedStartByte(u8),
UnexpectedContinuationByte(u8),
}
impl fmt::Display for Utf8ParserError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::InvalidByte(byte) => {
write!(f, "Found invalid byte: 0x{byte:02x}")
}
Self::InvalidChar(word) => {
write!(f, "Parsed invalid UTF-8 code point: 0x{word:04x}")
}
Self::UnexpectedStartByte(byte) => {
write!(
f,
"Found start byte when a continuation byte was expected: 0x{byte:02x}"
)
}
Self::UnexpectedContinuationByte(byte) => {
write!(
f,
"Found continuation byte when a start byte was expected: 0x{byte:02x}"
)
}
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for Utf8ParserError {}