ferroui_base/data/core/
expression_parse_exception.rs1use std::fmt;
4
5#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct ExpressionParseException {
8 column: i32,
9 message: String,
10}
11
12impl ExpressionParseException {
13 pub fn new(column: i32, message: impl Into<String>) -> Self {
18 Self {
19 column,
20 message: message.into(),
21 }
22 }
23
24 #[inline]
26 pub fn column(&self) -> i32 {
27 self.column
28 }
29
30 #[inline]
32 pub fn message(&self) -> &str {
33 &self.message
34 }
35}
36
37impl fmt::Display for ExpressionParseException {
38 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39 f.write_str(&self.message)
40 }
41}
42
43impl std::error::Error for ExpressionParseException {}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn exposes_column_and_message() {
51 let e = ExpressionParseException::new(3, "Expected ')'.");
52 assert_eq!(e.column(), 3);
53 assert_eq!(e.message(), "Expected ')'.");
54 assert_eq!(e.to_string(), "Expected ')'.");
55 let _: &dyn std::error::Error = &e;
56 }
57}