icu_datetime/provider/pattern/
error.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
5use crate::provider::fields;
6use displaydoc::Display;
7
8/// A low-level pattern parsing error.
9///
10/// These strings follow the recommendations for the serde::de::Unexpected::Other type.
11/// <https://docs.serde.rs/serde/de/enum.Unexpected.html#variant.Other>
12///
13/// Serde will generate an error such as:
14/// "invalid value: unclosed literal in pattern, expected a valid UTS 35 pattern string at line 1 column 12"
15#[derive(Display, Debug, PartialEq, Copy, Clone)]
16#[allow(missing_docs)]
17#[non_exhaustive]
18pub enum PatternError {
19    #[displaydoc("{0:?} invalid field length in pattern")]
20    FieldLengthInvalid(fields::FieldSymbol),
21    #[displaydoc("unknown substitution {0} in pattern")]
22    UnknownSubstitution(char),
23    #[displaydoc("invalid symbol {0} in pattern")]
24    InvalidSymbol(char),
25    #[displaydoc("unclosed literal in pattern")]
26    UnclosedLiteral,
27    #[displaydoc("unclosed placeholder in pattern")]
28    UnclosedPlaceholder,
29    #[displaydoc("plural pattern variants are only supported for week-of-month and week-of-year")]
30    UnsupportedPluralPivot,
31}
32
33impl core::error::Error for PatternError {}
34
35impl From<fields::Error> for PatternError {
36    fn from(input: fields::Error) -> Self {
37        match input {
38            fields::Error::InvalidLength(symbol) => Self::FieldLengthInvalid(symbol),
39        }
40    }
41}