Skip to main content

ferroui_base/rendering/composition/expressions/
expression_parse_exception.rs

1//! The error of the expression parser.
2
3use std::error::Error;
4use std::fmt;
5
6/// The error raised when a composition expression cannot be parsed.
7#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct ExpressionParseException {
9    message: String,
10    position: i32,
11}
12
13impl ExpressionParseException {
14    /// Creates the error with a message and the position (in UTF-16 code
15    /// units from the start of the expression) it was detected at.
16    pub fn new(message: impl Into<String>, position: i32) -> Self {
17        Self {
18            message: message.into(),
19            position,
20        }
21    }
22
23    /// The message of the error.
24    pub fn message(&self) -> &str {
25        &self.message
26    }
27
28    /// The position the error was detected at.
29    pub fn position(&self) -> i32 {
30        self.position
31    }
32}
33
34impl fmt::Display for ExpressionParseException {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        f.write_str(&self.message)
37    }
38}
39
40impl Error for ExpressionParseException {}