icu_datetime/
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::pattern::PatternLoadError;
6use displaydoc::Display;
7use icu_calendar::AnyCalendarKind;
8use icu_provider::DataError;
9
10/// An error from constructing a formatter.
11#[derive(Display, Debug, Copy, Clone, PartialEq)]
12#[non_exhaustive]
13pub enum DateTimeFormatterLoadError {
14    /// An error while loading display names for a field.
15    #[displaydoc("{0}")]
16    Names(PatternLoadError),
17    /// An error while loading some other required data,
18    /// such as skeleton patterns or calendar conversions.
19    #[displaydoc("{0}")]
20    Data(DataError),
21}
22
23impl core::error::Error for DateTimeFormatterLoadError {}
24
25impl From<DataError> for DateTimeFormatterLoadError {
26    fn from(error: DataError) -> Self {
27        Self::Data(error)
28    }
29}
30
31/// The specific field for which an error occurred.
32#[derive(Display, Debug, Copy, Clone, PartialEq)]
33pub struct ErrorField(pub(crate) crate::provider::fields::Field);
34
35/// An error from mixing calendar types in a formatter.
36#[derive(Display, Debug, Copy, Clone, PartialEq)]
37#[displaydoc("DateTimeFormatter for {this_kind} calendar was given a {date_kind:?} calendar")]
38#[non_exhaustive]
39pub struct MismatchedCalendarError {
40    /// The calendar kind of the target object (formatter).
41    pub this_kind: AnyCalendarKind,
42    /// The calendar kind of the input object (date being formatted).
43    /// Can be `None` if the input calendar was not specified.
44    pub date_kind: Option<AnyCalendarKind>,
45}
46
47impl core::error::Error for MismatchedCalendarError {}