minify-html/src/err.rs

34 lines
985 B
Rust
Raw Normal View History

// Implement debug to allow .unwrap().
#[derive(Debug)]
2019-12-25 07:29:18 -05:00
pub enum ErrorType {
ClosingTagMismatch,
2019-12-25 07:29:18 -05:00
MatchNotFound(&'static [u8]),
NotFound(&'static str),
2020-01-08 08:49:17 -05:00
ExpectedChar(u8),
UnexpectedEnd,
}
2019-12-30 02:16:33 -05:00
impl ErrorType {
pub fn message(self) -> String {
match self {
ErrorType::ClosingTagMismatch => {
2020-01-12 06:49:41 -05:00
format!("Closing tag name does not match opening tag.")
}
2019-12-30 02:16:33 -05:00
ErrorType::MatchNotFound(seq) => {
format!("Expected `{}`.", unsafe { std::str::from_utf8_unchecked(seq) })
}
ErrorType::NotFound(exp) => {
format!("Expected {}.", exp)
}
2020-01-08 08:49:17 -05:00
ErrorType::ExpectedChar(unexp) => {
format!("Expected {} (U+{:X}).", unexp as char, unexp)
2019-12-30 02:16:33 -05:00
}
ErrorType::UnexpectedEnd => {
format!("Unexpected end of source code.")
}
}
}
}
pub type ProcessingResult<T> = Result<T, ErrorType>;