Skip to main content

egui_charts/model/
parse.rs

1//! The error of the text parsers in `model` and `scales`.
2
3use std::fmt;
4
5/// Why text did not parse as a colour, timeframe, time zone or price scale mode.
6#[derive(Clone, Debug, PartialEq, Eq)]
7pub struct ParseError {
8    kind: &'static str,
9    input: String,
10    reason: &'static str,
11}
12
13impl ParseError {
14    pub(crate) fn new(kind: &'static str, input: &str, reason: &'static str) -> Self {
15        Self {
16            kind,
17            input: input.to_owned(),
18            reason,
19        }
20    }
21
22    /// The text that did not parse, as given.
23    pub fn input(&self) -> &str {
24        &self.input
25    }
26}
27
28impl fmt::Display for ParseError {
29    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30        write!(f, "invalid {} {:?}: {}", self.kind, self.input, self.reason)
31    }
32}
33
34impl std::error::Error for ParseError {}