keyvalues_parser/
error.rs1use std::fmt;
4
5use crate::text::parse::{EscapedPestError, RawPestError};
6
7pub type Result<T> = std::result::Result<T, Error>;
9
10#[derive(Clone, Debug, PartialEq, Eq)]
19pub enum Error {
20 EscapedParseError(EscapedPestError),
21 RawParseError(RawPestError),
22 RenderError(fmt::Error),
23 RawRenderError { invalid_char: char },
24}
25
26impl From<EscapedPestError> for Error {
27 fn from(e: EscapedPestError) -> Self {
28 Self::EscapedParseError(e)
29 }
30}
31
32impl From<RawPestError> for Error {
33 fn from(e: RawPestError) -> Self {
34 Self::RawParseError(e)
35 }
36}
37
38impl From<std::fmt::Error> for Error {
39 fn from(e: std::fmt::Error) -> Self {
40 Self::RenderError(e)
41 }
42}
43
44impl fmt::Display for Error {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match self {
47 Self::EscapedParseError(e) => write!(f, "Failed parsing input Error: {e}"),
48 Self::RawParseError(e) => write!(f, "Failed parsing input Error: {e}"),
49 Self::RenderError(e) => write!(f, "Failed rendering input Error: {e}"),
50 Self::RawRenderError { invalid_char } => write!(
51 f,
52 "Encountered invalid character in raw string: {invalid_char:?}"
53 ),
54 }
55 }
56}
57
58impl std::error::Error for Error {}