icu_datetime/
external_loaders.rs
use icu_calendar::{AnyCalendar, AnyCalendarPreferences};
use icu_decimal::options::DecimalFormatterOptions;
use icu_decimal::{DecimalFormatter, DecimalFormatterPreferences};
use icu_provider::prelude::*;
pub(crate) trait DecimalFormatterLoader {
fn load(
&self,
prefs: DecimalFormatterPreferences,
options: DecimalFormatterOptions,
) -> Result<DecimalFormatter, DataError>;
}
pub(crate) trait AnyCalendarLoader {
fn load(&self, prefs: AnyCalendarPreferences) -> Result<AnyCalendar, DataError>;
}
#[cfg(feature = "compiled_data")]
pub(crate) struct ExternalLoaderCompiledData;
#[cfg(feature = "compiled_data")]
impl DecimalFormatterLoader for ExternalLoaderCompiledData {
#[inline]
fn load(
&self,
prefs: DecimalFormatterPreferences,
options: DecimalFormatterOptions,
) -> Result<DecimalFormatter, DataError> {
DecimalFormatter::try_new(prefs, options)
}
}
#[cfg(feature = "compiled_data")]
impl AnyCalendarLoader for ExternalLoaderCompiledData {
#[inline]
fn load(&self, prefs: AnyCalendarPreferences) -> Result<AnyCalendar, DataError> {
AnyCalendar::try_new(prefs)
}
}
#[cfg(feature = "serde")]
pub(crate) struct ExternalLoaderBuffer<'a, P: ?Sized>(pub &'a P);
#[cfg(feature = "serde")]
impl<P> DecimalFormatterLoader for ExternalLoaderBuffer<'_, P>
where
P: ?Sized + BufferProvider,
{
#[inline]
fn load(
&self,
prefs: DecimalFormatterPreferences,
options: DecimalFormatterOptions,
) -> Result<DecimalFormatter, DataError> {
DecimalFormatter::try_new_with_buffer_provider(self.0, prefs, options)
}
}
#[cfg(feature = "serde")]
impl<P> AnyCalendarLoader for ExternalLoaderBuffer<'_, P>
where
P: ?Sized + BufferProvider,
{
#[inline]
fn load(&self, prefs: AnyCalendarPreferences) -> Result<AnyCalendar, DataError> {
AnyCalendar::try_new_with_buffer_provider(self.0, prefs)
}
}
pub(crate) struct ExternalLoaderUnstable<'a, P: ?Sized>(pub &'a P);
impl<P> DecimalFormatterLoader for ExternalLoaderUnstable<'_, P>
where
P: ?Sized
+ DataProvider<icu_decimal::provider::DecimalSymbolsV1>
+ DataProvider<icu_decimal::provider::DecimalDigitsV1>,
{
#[inline]
fn load(
&self,
prefs: DecimalFormatterPreferences,
options: DecimalFormatterOptions,
) -> Result<DecimalFormatter, DataError> {
DecimalFormatter::try_new_unstable(self.0, prefs, options)
}
}
impl<P> AnyCalendarLoader for ExternalLoaderUnstable<'_, P>
where
P: DataProvider<icu_calendar::provider::CalendarJapaneseModernV1>
+ DataProvider<icu_calendar::provider::CalendarJapaneseExtendedV1>
+ DataProvider<icu_calendar::provider::CalendarChineseV1>
+ DataProvider<icu_calendar::provider::CalendarDangiV1>
+ DataProvider<icu_calendar::provider::CalendarHijriObservationalV1>
+ DataProvider<icu_calendar::provider::CalendarHijriUmmalquraV1>
+ ?Sized,
{
#[inline]
fn load(&self, prefs: AnyCalendarPreferences) -> Result<AnyCalendar, DataError> {
AnyCalendar::try_new_unstable(self.0, prefs)
}
}