email_address_list/
error.rs

1use crate::parser::Rule;
2use std::convert::From;
3use std::fmt;
4
5#[derive(Debug)]
6pub enum Error {
7    PestRuleError(Box<pest::error::Error<Rule>>),
8    UnexpectedError(String),
9    Empty,
10}
11
12impl fmt::Display for Error {
13    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14        write!(f, "{:?}", self)
15    }
16}
17
18impl From<pest::error::Error<Rule>> for Error {
19    fn from(s: pest::error::Error<Rule>) -> Error {
20        Error::PestRuleError(Box::new(s))
21    }
22}
23
24pub type Result<T> = std::result::Result<T, Error>;
25
26pub(crate) fn invalid_nesting(rule: &str) -> Error {
27    Error::UnexpectedError(format!("Invalid nesting in {} rule", rule))
28}
29
30pub(crate) fn invalid_empty(rule: &str) -> Error {
31    Error::UnexpectedError(format!("{} cannot be empty", rule))
32}