unicode_locale_parser/
errors.rs

1use std::error::Error;
2use std::fmt::{Display, Formatter, Result};
3
4/// Enum representing the possible errors that can occur when parsing [Unicode UTS #35 Language and Locale Identifiers](https://unicode.org/reports/tr35/#Identifiers).
5#[derive(Debug, PartialEq)]
6pub enum ParserError {
7    /// A missing identifier error.
8    Missing,
9    /// An invalid language identifier error.
10    InvalidLanguage,
11    /// An invalid subtag error.
12    InvalidSubtag,
13    /// An invalid unicode extensions error.
14    InvalidExtension,
15    /// An invalid unicode subdivision error.
16    InvalidSubdivision,
17    /// An unexpected error.
18    Unexpected,
19}
20
21impl Error for ParserError {}
22
23impl Display for ParserError {
24    fn fmt(&self, f: &mut Formatter) -> Result {
25        let value = match self {
26            ParserError::Missing => "Missing identifier",
27            ParserError::InvalidLanguage => "Invalid language identifier",
28            ParserError::InvalidSubtag => "Invalid subtag",
29            ParserError::InvalidExtension => "Invalid extension",
30            ParserError::InvalidSubdivision => "Invalid subdivision",
31            ParserError::Unexpected => "Unexpected error",
32        };
33        f.write_str(value)
34    }
35}