use std::fmt;
#[derive(Debug)]
pub struct ParseError {
message: String,
}
impl ParseError {
pub(crate) fn new(message: impl Into<String>) -> Self {
Self {
message: message.into(),
}
}
}
impl fmt::Display for ParseError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "parse error: {}", self.message)
}
}
impl std::error::Error for ParseError {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn error_display() {
let err = ParseError::new("unexpected token");
assert_eq!(err.to_string(), "parse error: unexpected token");
}
}