1 | // This file is part of ICU4X. For terms of use, please see the file |
2 | // called LICENSE at the top level of the ICU4X source tree |
3 | // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
4 | |
5 | use displaydoc::Display; |
6 | |
7 | /// List of parser errors that can be generated |
8 | /// while parsing [`LanguageIdentifier`](crate::LanguageIdentifier), [`Locale`](crate::Locale), |
9 | /// [`subtags`](crate::subtags) or [`extensions`](crate::extensions). |
10 | /// |
11 | /// Re-exported as [`Error`](crate::Error). |
12 | #[derive (Display, Debug, PartialEq, Copy, Clone)] |
13 | #[non_exhaustive ] |
14 | pub enum ParserError { |
15 | /// Invalid language subtag. |
16 | /// |
17 | /// # Examples |
18 | /// |
19 | /// ``` |
20 | /// use icu::locid::subtags::Language; |
21 | /// use icu::locid::ParserError; |
22 | /// |
23 | /// assert_eq!("x2" .parse::<Language>(), Err(ParserError::InvalidLanguage)); |
24 | /// ``` |
25 | #[displaydoc("The given language subtag is invalid" )] |
26 | InvalidLanguage, |
27 | |
28 | /// Invalid script, region or variant subtag. |
29 | /// |
30 | /// # Examples |
31 | /// |
32 | /// ``` |
33 | /// use icu::locid::subtags::Region; |
34 | /// use icu::locid::ParserError; |
35 | /// |
36 | /// assert_eq!("#@2X" .parse::<Region>(), Err(ParserError::InvalidSubtag)); |
37 | /// ``` |
38 | #[displaydoc("Invalid subtag" )] |
39 | InvalidSubtag, |
40 | |
41 | /// Invalid extension subtag. |
42 | /// |
43 | /// # Examples |
44 | /// |
45 | /// ``` |
46 | /// use icu::locid::extensions::unicode::Key; |
47 | /// use icu::locid::ParserError; |
48 | /// |
49 | /// assert_eq!("#@2X" .parse::<Key>(), Err(ParserError::InvalidExtension)); |
50 | /// ``` |
51 | #[displaydoc("Invalid extension" )] |
52 | InvalidExtension, |
53 | |
54 | /// Duplicated extension. |
55 | /// |
56 | /// # Examples |
57 | /// |
58 | /// ``` |
59 | /// use icu::locid::Locale; |
60 | /// use icu::locid::ParserError; |
61 | /// |
62 | /// assert_eq!( |
63 | /// "und-u-hc-h12-u-ca-calendar" .parse::<Locale>(), |
64 | /// Err(ParserError::DuplicatedExtension) |
65 | /// ); |
66 | /// ``` |
67 | #[displaydoc("Duplicated extension" )] |
68 | DuplicatedExtension, |
69 | } |
70 | |
71 | #[cfg (feature = "std" )] |
72 | impl std::error::Error for ParserError {} |
73 | |