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)]
20pub enum Error {
21 EscapedParseError(EscapedPestError),
22 RawParseError(RawPestError),
23 RenderError(fmt::Error),
24 RawRenderError { invalid_char: char },
25}
26
27impl From<EscapedPestError> for Error {
28 fn from(e: EscapedPestError) -> Self {
29 Self::EscapedParseError(e)
30 }
31}
32
33impl From<RawPestError> for Error {
34 fn from(e: RawPestError) -> Self {
35 Self::RawParseError(e)
36 }
37}
38
39impl From<std::fmt::Error> for Error {
40 fn from(e: std::fmt::Error) -> Self {
41 Self::RenderError(e)
42 }
43}
44
45impl fmt::Display for Error {
46 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
47 match self {
48 Self::EscapedParseError(e) => write!(f, "Failed parsing input Error: {e}"),
49 Self::RawParseError(e) => write!(f, "Failed parsing input Error: {e}"),
50 Self::RenderError(e) => write!(f, "Failed rendering input Error: {e}"),
51 Self::RawRenderError { invalid_char } => write!(
52 f,
53 "Encountered invalid character in raw string: {invalid_char:?}"
54 ),
55 }
56 }
57}
58
59impl std::error::Error for Error {}