Debian Codegraph @

debian/rust-vendor/icu_pattern/src/parser/error.rs

raw
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 core::fmt::Debug;
6 use displaydoc::Display;
7
8 /// An error returned when parsing a pattern.
9 ///
10 /// ✨ *Enabled with the `alloc` Cargo feature.*
11 ///
12 /// # Examples
13 /// ```
14 /// use icu_pattern::{Parser, ParserError, ParserOptions};
15 ///
16 /// let mut parser = Parser::<usize>::new("{0", ParserOptions::default());
17 /// assert_eq!(Err(ParserError::UnclosedPlaceholder), parser.try_next());
18 /// ```
19 ///
20 /// # Type parameters
21 ///
22 /// - `E`: An error of the replacement type which implements [`FromStr`].
23 ///
24 /// [`FromStr`]: core::str::FromStr
25 #[derive(Display, Debug, PartialEq)]
26 #[non_exhaustive]
27 pub enum ParserError<E>
28 where
29 E: Debug,
30 {
31 /// Encountered an illegal character.
32 #[displaydoc("Illegal character: {0}.")]
33 IllegalCharacter(char),
34
35 /// Placeholder hould not be parsed from the given string slice.
36 #[displaydoc("Invalid placeholder: {0:?}")]
37 InvalidPlaceholder(E),
38
39 /// The pattern contains an unclosed placeholder.
40 #[displaydoc("Unclosed placeholder")]
41 UnclosedPlaceholder,
42
43 /// The pattern contains an unclosed quoted literal.
44 #[displaydoc("Unclosed quoted literal")]
45 UnclosedQuotedLiteral,
46 }
47
48 impl<E: Debug> core::error::Error for ParserError<E> {}