• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zbraniecki / icu4x / 9457158389

10 Jun 2024 11:45PM UTC coverage: 75.174% (+0.05%) from 75.121%
9457158389

push

github

web-flow
Add constructing TinyAsciiStr from utf16 (#5025)

Introduces TinyAsciiStr constructors from utf16 and converges on the
consensus from #4931.

---------

Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>

65 of 82 new or added lines in 14 files covered. (79.27%)

3441 existing lines in 141 files now uncovered.

52850 of 70304 relevant lines covered (75.17%)

563298.06 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

5.56
/components/datetime/src/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

5
use crate::fields::Field;
6
use crate::fields::FieldSymbol;
7
use crate::pattern::PatternError;
8
use displaydoc::Display;
9
use icu_calendar::any_calendar::AnyCalendarKind;
10
use icu_calendar::types::MonthCode;
11
use icu_provider::DataError;
12

13
#[cfg(feature = "std")]
14
impl std::error::Error for DateTimeError {}
15

16
/// A list of error outcomes for various operations in this module.
17
#[derive(Display, Debug, Copy, Clone, PartialEq)]
1✔
18
#[non_exhaustive]
19
pub enum DateTimeError {
20
    /// An error originating from parsing a pattern.
UNCOV
21
    #[displaydoc("{0}")]
×
UNCOV
22
    Pattern(PatternError),
×
23
    /// An error originating from the [`Write`](std::fmt::Write) trait.
UNCOV
24
    #[displaydoc("{0}")]
×
UNCOV
25
    Format(core::fmt::Error),
×
26
    /// An error originating inside of the [data provider](icu_provider).
27
    #[displaydoc("{0}")]
×
UNCOV
28
    Data(DataError),
×
29
    /// An error originating from a missing field in datetime input.
30
    /// TODO: How can we return which field was missing?
31
    #[displaydoc("Missing input field")]
32
    MissingInputField(Option<&'static str>),
1✔
33
    /// An error originating from skeleton matching.
UNCOV
34
    #[displaydoc("{0}")]
×
35
    #[cfg(feature = "experimental")]
UNCOV
36
    Skeleton(crate::skeleton::SkeletonError),
×
37
    /// An error originating from an unsupported field in a datetime format.
38
    #[displaydoc("Unsupported field: {0:?}")]
39
    UnsupportedField(FieldSymbol),
×
40
    /// An unsupported field with a field length.
41
    // TODO(#2856): Consider renaming `UnsupportedField` to `UnsupportedFieldSymbol` so that
42
    // this variant can be named `UnsupportedField`.
43
    #[displaydoc("Unsupported field: {0:?}")]
44
    UnsupportedFormattingField(Field),
×
45
    /// An error due to there being no patterns for the given options.
46
    #[displaydoc("Unsupported options")]
47
    UnsupportedOptions,
48
    /// An error originating from a missing weekday symbol in the data.
49
    #[displaydoc("Data file missing weekday symbol for weekday {0}")]
×
UNCOV
50
    MissingWeekdaySymbol(usize),
×
51
    /// An error originating from a missing month symbol in the data.
UNCOV
52
    #[displaydoc("Data file missing month symbol for month code {0}")]
×
UNCOV
53
    MissingMonthSymbol(MonthCode),
×
54
    /// The FixedDecimalFormatter is not loaded
55
    #[displaydoc("Missing FixedDecimalFormatter")]
56
    FixedDecimal,
57
    /// An error from mixing calendar types in [`DateTimeFormatter`](crate::DateTimeFormatter)
58
    #[displaydoc("DateTimeFormatter for {0} calendar was given a {1:?} calendar")]
×
UNCOV
59
    MismatchedAnyCalendar(AnyCalendarKind, Option<AnyCalendarKind>),
×
60
    /// Missing date symbols
61
    #[displaydoc("Missing date symbols")]
62
    MissingDateSymbols,
63
    /// Missing time symbols
64
    #[displaydoc("Missing time symbols")]
65
    MissingTimeSymbols,
66
    /// ordinal_rules must be set for PatternPlurals::MultipleVariants
67
    #[displaydoc("ordinal_rules must be set for PatternPlurals::MultipleVariants")]
68
    MissingOrdinalRules,
69
    /// The names for the given field are not loaded
70
    #[displaydoc("Missing names for {0:?}")]
UNCOV
71
    MissingNames(Field),
×
72
    /// The same field occurs multiple times in a pattern or was loaded multiple times
73
    #[displaydoc("Duplicate field: {0:?}")]
UNCOV
74
    DuplicateField(Field),
×
75
}
76

77
/// An error from mixing calendar types in [`DateTimeFormatter`](crate::DateTimeFormatter)
UNCOV
78
#[derive(Display, Debug, Copy, Clone, PartialEq)]
×
UNCOV
79
#[displaydoc("DateTimeFormatter for {this_kind} calendar was given a {date_kind:?} calendar")]
×
80
#[non_exhaustive]
81
pub struct MismatchedCalendarError {
82
    /// The calendar kind of the target object (formatter).
UNCOV
83
    pub this_kind: AnyCalendarKind,
×
84
    /// The calendar kind of the input object (date being formatted).
85
    /// Can be `None` if the input calendar was not specified.
UNCOV
86
    pub date_kind: Option<AnyCalendarKind>,
×
87
}
88

89
impl From<PatternError> for DateTimeError {
UNCOV
90
    fn from(e: PatternError) -> Self {
×
UNCOV
91
        DateTimeError::Pattern(e)
×
92
    }
×
93
}
94

95
impl From<DataError> for DateTimeError {
UNCOV
96
    fn from(e: DataError) -> Self {
×
97
        DateTimeError::Data(e)
×
UNCOV
98
    }
×
99
}
100

101
impl From<core::fmt::Error> for DateTimeError {
UNCOV
102
    fn from(e: core::fmt::Error) -> Self {
×
UNCOV
103
        DateTimeError::Format(e)
×
104
    }
×
105
}
106

107
impl From<MismatchedCalendarError> for DateTimeError {
UNCOV
108
    fn from(e: MismatchedCalendarError) -> Self {
×
UNCOV
109
        DateTimeError::MismatchedAnyCalendar(e.this_kind, e.date_kind)
×
110
    }
×
111
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc