use std::fmt;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ExpressionParseException {
column: i32,
message: String,
}
impl ExpressionParseException {
pub fn new(column: i32, message: impl Into<String>) -> Self {
Self {
column,
message: message.into(),
}
}
#[inline]
pub fn column(&self) -> i32 {
self.column
}
#[inline]
pub fn message(&self) -> &str {
&self.message
}
}
impl fmt::Display for ExpressionParseException {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.message)
}
}
impl std::error::Error for ExpressionParseException {}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn exposes_column_and_message() {
let e = ExpressionParseException::new(3, "Expected ')'.");
assert_eq!(e.column(), 3);
assert_eq!(e.message(), "Expected ')'.");
assert_eq!(e.to_string(), "Expected ')'.");
let _: &dyn std::error::Error = &e;
}
}