]> git.proxmox.com Git - rustc.git/blob - vendor/icu_locid/src/parser/errors.rs
New upstream version 1.69.0+dfsg1
[rustc.git] / vendor / icu_locid / src / parser / errors.rs
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 #[derive(Display, Debug, PartialEq, Copy, Clone)]
11 #[non_exhaustive]
12 pub enum ParserError {
13 /// Invalid language subtag.
14 ///
15 /// # Examples
16 ///
17 /// ```
18 /// use icu::locid::subtags::Language;
19 /// use icu::locid::ParserError;
20 ///
21 /// assert_eq!("x2".parse::<Language>(), Err(ParserError::InvalidLanguage));
22 /// ```
23 #[displaydoc("The given language subtag is invalid")]
24 InvalidLanguage,
25
26 /// Invalid script, region or variant subtag.
27 ///
28 /// # Examples
29 ///
30 /// ```
31 /// use icu::locid::subtags::Region;
32 /// use icu::locid::ParserError;
33 ///
34 /// assert_eq!("#@2X".parse::<Region>(), Err(ParserError::InvalidSubtag));
35 /// ```
36 #[displaydoc("Invalid subtag")]
37 InvalidSubtag,
38
39 /// Invalid extension subtag.
40 ///
41 /// # Examples
42 ///
43 /// ```
44 /// use icu::locid::extensions::unicode::Key;
45 /// use icu::locid::ParserError;
46 ///
47 /// assert_eq!("#@2X".parse::<Key>(), Err(ParserError::InvalidExtension));
48 /// ```
49 #[displaydoc("Invalid extension")]
50 InvalidExtension,
51
52 /// Duplicated extension.
53 ///
54 /// # Examples
55 ///
56 /// ```
57 /// use icu::locid::Locale;
58 /// use icu::locid::ParserError;
59 ///
60 /// assert_eq!(
61 /// "und-u-hc-h12-u-ca-calendar".parse::<Locale>(),
62 /// Err(ParserError::DuplicatedExtension)
63 /// );
64 /// ```
65 #[displaydoc("Duplicated extension")]
66 DuplicatedExtension,
67 }
68
69 #[cfg(feature = "std")]
70 impl std::error::Error for ParserError {}