use std::fmt;
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct SyntaxError {
pub line: u32,
pub msg: Vec<u8>,
}
impl SyntaxError {
pub fn new(line: u32, msg: impl Into<Vec<u8>>) -> Self {
SyntaxError {
line,
msg: msg.into(),
}
}
pub fn msg_str(&self) -> std::borrow::Cow<'_, str> {
String::from_utf8_lossy(&self.msg)
}
}
impl fmt::Display for SyntaxError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}: {}", self.line, self.msg_str())
}
}
impl std::error::Error for SyntaxError {}