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

zbraniecki / icu4x / 13958601093

19 Mar 2025 04:17PM UTC coverage: 74.164% (-1.5%) from 75.71%
13958601093

push

github

web-flow
Clean up properties docs (#6315)

58056 of 78281 relevant lines covered (74.16%)

819371.32 hits per line

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

20.0
/components/datetime/src/external_loaders.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
//! Internal traits and structs for loading data from other crates.
6

7
use icu_calendar::{AnyCalendar, AnyCalendarPreferences};
8
use icu_decimal::options::DecimalFormatterOptions;
9
use icu_decimal::{DecimalFormatter, DecimalFormatterPreferences};
10
use icu_provider::prelude::*;
11

12
/// Trait for loading a DecimalFormatter.
13
///
14
/// Implemented on the provider-specific loader types in this module.
15
pub(crate) trait DecimalFormatterLoader {
16
    fn load(
17
        &self,
18
        prefs: DecimalFormatterPreferences,
19
        options: DecimalFormatterOptions,
20
    ) -> Result<DecimalFormatter, DataError>;
21
}
22

23
/// Trait for loading an AnyCalendar.
24
///
25
/// Implemented on the provider-specific loader types in this module.
26
pub(crate) trait AnyCalendarLoader {
27
    fn load(&self, prefs: AnyCalendarPreferences) -> Result<AnyCalendar, DataError>;
28
}
29

30
/// Loader for types from other crates using compiled data.
31
#[cfg(feature = "compiled_data")]
32
pub(crate) struct ExternalLoaderCompiledData;
33

34
#[cfg(feature = "compiled_data")]
35
impl DecimalFormatterLoader for ExternalLoaderCompiledData {
36
    #[inline]
37
    fn load(
36✔
38
        &self,
39
        prefs: DecimalFormatterPreferences,
40
        options: DecimalFormatterOptions,
41
    ) -> Result<DecimalFormatter, DataError> {
42
        DecimalFormatter::try_new(prefs, options)
36✔
43
    }
36✔
44
}
45

46
#[cfg(feature = "compiled_data")]
47
impl AnyCalendarLoader for ExternalLoaderCompiledData {
48
    #[inline]
49
    fn load(&self, prefs: AnyCalendarPreferences) -> Result<AnyCalendar, DataError> {
×
50
        AnyCalendar::try_new(prefs)
×
51
    }
×
52
}
53

54
/// Loader for types from other crates using [`BufferProvider`].
55
#[cfg(feature = "serde")]
56
pub(crate) struct ExternalLoaderBuffer<'a, P: ?Sized>(pub &'a P);
57

58
#[cfg(feature = "serde")]
59
impl<P> DecimalFormatterLoader for ExternalLoaderBuffer<'_, P>
60
where
61
    P: ?Sized + BufferProvider,
62
{
63
    #[inline]
64
    fn load(
×
65
        &self,
66
        prefs: DecimalFormatterPreferences,
67
        options: DecimalFormatterOptions,
68
    ) -> Result<DecimalFormatter, DataError> {
69
        DecimalFormatter::try_new_with_buffer_provider(self.0, prefs, options)
×
70
    }
×
71
}
72

73
#[cfg(feature = "serde")]
74
impl<P> AnyCalendarLoader for ExternalLoaderBuffer<'_, P>
75
where
76
    P: ?Sized + BufferProvider,
77
{
78
    #[inline]
79
    fn load(&self, prefs: AnyCalendarPreferences) -> Result<AnyCalendar, DataError> {
×
80
        AnyCalendar::try_new_with_buffer_provider(self.0, prefs)
×
81
    }
×
82
}
83

84
/// Loader for types from other crates using [`DataProvider`].
85
pub(crate) struct ExternalLoaderUnstable<'a, P: ?Sized>(pub &'a P);
86

87
impl<P> DecimalFormatterLoader for ExternalLoaderUnstable<'_, P>
88
where
89
    P: ?Sized
90
        + DataProvider<icu_decimal::provider::DecimalSymbolsV1>
91
        + DataProvider<icu_decimal::provider::DecimalDigitsV1>,
92
{
93
    #[inline]
94
    fn load(
×
95
        &self,
96
        prefs: DecimalFormatterPreferences,
97
        options: DecimalFormatterOptions,
98
    ) -> Result<DecimalFormatter, DataError> {
99
        DecimalFormatter::try_new_unstable(self.0, prefs, options)
×
100
    }
×
101
}
102

103
impl<P> AnyCalendarLoader for ExternalLoaderUnstable<'_, P>
104
where
105
    P: DataProvider<icu_calendar::provider::CalendarJapaneseModernV1>
106
        + DataProvider<icu_calendar::provider::CalendarJapaneseExtendedV1>
107
        + DataProvider<icu_calendar::provider::CalendarChineseV1>
108
        + DataProvider<icu_calendar::provider::CalendarDangiV1>
109
        + DataProvider<icu_calendar::provider::CalendarHijriObservationalV1>
110
        + DataProvider<icu_calendar::provider::CalendarHijriUmmalquraV1>
111
        + ?Sized,
112
{
113
    #[inline]
114
    fn load(&self, prefs: AnyCalendarPreferences) -> Result<AnyCalendar, DataError> {
115
        AnyCalendar::try_new_unstable(self.0, prefs)
116
    }
117
}
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