1 | use super::parser::ParserError; |
2 | use std::error::Error; |
3 | use std::fmt::{self, Display}; |
4 | |
5 | /// Enum with errors that can be returned by LanguageIdentifier. |
6 | #[derive (Debug, PartialEq)] |
7 | pub enum LanguageIdentifierError { |
8 | /// An unknown error - currently covers all-but parser errors. |
9 | Unknown, |
10 | /// A parser error. |
11 | ParserError(ParserError), |
12 | } |
13 | |
14 | impl From<ParserError> for LanguageIdentifierError { |
15 | fn from(error: ParserError) -> LanguageIdentifierError { |
16 | LanguageIdentifierError::ParserError(error) |
17 | } |
18 | } |
19 | |
20 | impl Error for LanguageIdentifierError {} |
21 | |
22 | impl Display for LanguageIdentifierError { |
23 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
24 | match self { |
25 | LanguageIdentifierError::Unknown => write!(f, "Unknown error" ), |
26 | LanguageIdentifierError::ParserError(p: &ParserError) => write!(f, "Parser error: {}" , p), |
27 | } |
28 | } |
29 | } |
30 | |