use crate::provider::calendar::*;
use icu_calendar::any_calendar::AnyCalendarKind;
use icu_calendar::chinese::Chinese;
use icu_calendar::roc::Roc;
use icu_calendar::AnyCalendar;
use icu_calendar::{
buddhist::Buddhist, coptic::Coptic, dangi::Dangi, ethiopian::Ethiopian, hebrew::Hebrew,
indian::Indian, islamic::IslamicCivil, islamic::IslamicObservational, islamic::IslamicTabular,
islamic::IslamicUmmAlQura, japanese::Japanese, japanese::JapaneseExtended, persian::Persian,
Gregorian,
};
use icu_locid::extensions::unicode::{value, Value};
use icu_provider::prelude::*;
use tinystr::{tinystr, TinyAsciiStr};
#[cfg(any(feature = "datagen", feature = "experimental"))]
use crate::provider::neo::*;
#[cfg(feature = "experimental")]
use core::marker::PhantomData;
#[cfg(any(feature = "datagen", feature = "experimental"))]
use icu_provider::NeverMarker;
pub trait InternalCldrCalendar {}
pub trait CldrCalendar: InternalCldrCalendar {
const DEFAULT_BCP_47_IDENTIFIER: Value;
type DateSymbolsV1Marker: KeyedDataMarker<Yokeable = DateSymbolsV1<'static>>;
type DateLengthsV1Marker: KeyedDataMarker<Yokeable = DateLengthsV1<'static>>;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker: KeyedDataMarker<Yokeable = YearNamesV1<'static>>;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker: KeyedDataMarker<Yokeable = MonthNamesV1<'static>>;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker: KeyedDataMarker<Yokeable = DatePatternV1<'static>>;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker: KeyedDataMarker<Yokeable = PackedSkeletonDataV1<'static>>;
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
*value == Self::DEFAULT_BCP_47_IDENTIFIER
}
}
fn is_islamic_subcal(value: &Value, subcal: TinyAsciiStr<8>) -> bool {
if let &[first, second] = value.as_tinystr_slice() {
first == "islamic" && second == subcal
} else {
false
}
}
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)] #[cfg(any(feature = "datagen", feature = "experimental"))]
pub enum NeverCalendar {}
#[cfg(any(feature = "datagen", feature = "experimental"))]
impl CldrCalendar for NeverCalendar {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("never");
type DateSymbolsV1Marker = NeverMarker<DateSymbolsV1<'static>>;
type DateLengthsV1Marker = NeverMarker<DateLengthsV1<'static>>;
type YearNamesV1Marker = NeverMarker<YearNamesV1<'static>>;
type MonthNamesV1Marker = NeverMarker<MonthNamesV1<'static>>;
type DatePatternV1Marker = NeverMarker<DatePatternV1<'static>>;
type SkeletaV1Marker = NeverMarker<PackedSkeletonDataV1<'static>>;
}
impl CldrCalendar for Buddhist {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("buddhist");
type DateSymbolsV1Marker = BuddhistDateSymbolsV1Marker;
type DateLengthsV1Marker = BuddhistDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = BuddhistYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = BuddhistMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = BuddhistDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = BuddhistDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for Chinese {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("chinese");
type DateSymbolsV1Marker = ChineseDateSymbolsV1Marker;
type DateLengthsV1Marker = ChineseDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = ChineseYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = ChineseMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = ChineseDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = ChineseDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for Coptic {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("coptic");
type DateSymbolsV1Marker = CopticDateSymbolsV1Marker;
type DateLengthsV1Marker = CopticDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = CopticYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = CopticMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = CopticDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = CopticDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for Dangi {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("dangi");
type DateSymbolsV1Marker = DangiDateSymbolsV1Marker;
type DateLengthsV1Marker = DangiDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = DangiYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = DangiMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = DangiDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = DangiDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for Ethiopian {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("ethiopic");
type DateSymbolsV1Marker = EthiopianDateSymbolsV1Marker;
type DateLengthsV1Marker = EthiopianDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = EthiopianYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = EthiopianMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = EthiopianDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = EthiopianDateNeoSkeletonPatternsV1Marker;
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
*value == value!("ethiopic") || *value == value!("ethioaa")
}
}
impl CldrCalendar for Gregorian {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("gregory");
type DateSymbolsV1Marker = GregorianDateSymbolsV1Marker;
type DateLengthsV1Marker = GregorianDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = GregorianYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = GregorianMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = GregorianDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = GregorianDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for Hebrew {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("hebrew");
type DateSymbolsV1Marker = HebrewDateSymbolsV1Marker;
type DateLengthsV1Marker = HebrewDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = HebrewYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = HebrewMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = HebrewDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = HebrewDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for Indian {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("indian");
type DateSymbolsV1Marker = IndianDateSymbolsV1Marker;
type DateLengthsV1Marker = IndianDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = IndianYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = IndianMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = IndianDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = IndianDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for IslamicCivil {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("islamic");
type DateSymbolsV1Marker = IslamicDateSymbolsV1Marker;
type DateLengthsV1Marker = IslamicDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = IslamicYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = IslamicMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = IslamicDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker;
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
*value == value!("islamicc") || is_islamic_subcal(value, tinystr!(8, "civil"))
}
}
impl CldrCalendar for IslamicObservational {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("islamic");
type DateSymbolsV1Marker = IslamicDateSymbolsV1Marker;
type DateLengthsV1Marker = IslamicDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = IslamicYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = IslamicMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = IslamicDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for IslamicTabular {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("islamic");
type DateSymbolsV1Marker = IslamicDateSymbolsV1Marker;
type DateLengthsV1Marker = IslamicDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = IslamicYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = IslamicMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = IslamicDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker;
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
is_islamic_subcal(value, tinystr!(8, "tbla"))
}
}
impl CldrCalendar for IslamicUmmAlQura {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("islamic");
type DateSymbolsV1Marker = IslamicDateSymbolsV1Marker;
type DateLengthsV1Marker = IslamicDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = IslamicYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = IslamicMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = IslamicDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = IslamicDateNeoSkeletonPatternsV1Marker;
fn is_identifier_allowed_for_calendar(value: &Value) -> bool {
is_islamic_subcal(value, tinystr!(8, "umalqura"))
}
}
impl CldrCalendar for Japanese {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("japanese");
type DateSymbolsV1Marker = JapaneseDateSymbolsV1Marker;
type DateLengthsV1Marker = JapaneseDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = JapaneseYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = JapaneseMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = JapaneseDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = JapaneseDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for JapaneseExtended {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("japanext");
type DateSymbolsV1Marker = JapaneseExtendedDateSymbolsV1Marker;
type DateLengthsV1Marker = JapaneseExtendedDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = JapaneseExtendedYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = JapaneseExtendedMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = JapaneseExtendedDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = JapaneseExtendedDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for Persian {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("persian");
type DateSymbolsV1Marker = PersianDateSymbolsV1Marker;
type DateLengthsV1Marker = PersianDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = PersianYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = PersianMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = PersianDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = PersianDateNeoSkeletonPatternsV1Marker;
}
impl CldrCalendar for Roc {
const DEFAULT_BCP_47_IDENTIFIER: Value = value!("roc");
type DateSymbolsV1Marker = RocDateSymbolsV1Marker;
type DateLengthsV1Marker = RocDateLengthsV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type YearNamesV1Marker = RocYearNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type MonthNamesV1Marker = RocMonthNamesV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type DatePatternV1Marker = RocDatePatternV1Marker;
#[cfg(any(feature = "datagen", feature = "experimental"))]
type SkeletaV1Marker = RocDateNeoSkeletonPatternsV1Marker;
}
#[cfg(any(feature = "datagen", feature = "experimental"))]
impl InternalCldrCalendar for NeverCalendar {}
impl InternalCldrCalendar for Buddhist {}
impl InternalCldrCalendar for Chinese {}
impl InternalCldrCalendar for Coptic {}
impl InternalCldrCalendar for Dangi {}
impl InternalCldrCalendar for Ethiopian {}
impl InternalCldrCalendar for Gregorian {}
impl InternalCldrCalendar for Hebrew {}
impl InternalCldrCalendar for Indian {}
impl InternalCldrCalendar for IslamicCivil {}
impl InternalCldrCalendar for IslamicObservational {}
impl InternalCldrCalendar for IslamicTabular {}
impl InternalCldrCalendar for IslamicUmmAlQura {}
impl InternalCldrCalendar for Japanese {}
impl InternalCldrCalendar for JapaneseExtended {}
impl InternalCldrCalendar for Persian {}
impl InternalCldrCalendar for Roc {}
pub(crate) fn load_lengths_for_cldr_calendar<C, P>(
provider: &P,
locale: &DataLocale,
) -> Result<DataPayload<ErasedDateLengthsV1Marker>, DataError>
where
C: CldrCalendar,
P: DataProvider<<C as CldrCalendar>::DateLengthsV1Marker> + ?Sized,
{
let payload = provider
.load(DataRequest {
locale,
metadata: Default::default(),
})?
.take_payload()?;
Ok(payload.cast())
}
pub(crate) fn load_symbols_for_cldr_calendar<C, P>(
provider: &P,
locale: &DataLocale,
) -> Result<DataPayload<ErasedDateSymbolsV1Marker>, DataError>
where
C: CldrCalendar,
P: DataProvider<<C as CldrCalendar>::DateSymbolsV1Marker> + ?Sized,
{
let payload = provider
.load(DataRequest {
locale,
metadata: Default::default(),
})?
.take_payload()?;
Ok(payload.cast())
}
pub(crate) fn load_lengths_for_any_calendar_kind<P>(
provider: &P,
locale: &DataLocale,
kind: AnyCalendarKind,
) -> Result<DataPayload<ErasedDateLengthsV1Marker>, DataError>
where
P: DataProvider<BuddhistDateLengthsV1Marker>
+ DataProvider<ChineseDateLengthsV1Marker>
+ DataProvider<CopticDateLengthsV1Marker>
+ DataProvider<DangiDateLengthsV1Marker>
+ DataProvider<EthiopianDateLengthsV1Marker>
+ DataProvider<GregorianDateLengthsV1Marker>
+ DataProvider<HebrewDateLengthsV1Marker>
+ DataProvider<IndianDateLengthsV1Marker>
+ DataProvider<IslamicDateLengthsV1Marker>
+ DataProvider<JapaneseDateLengthsV1Marker>
+ DataProvider<JapaneseExtendedDateLengthsV1Marker>
+ DataProvider<PersianDateLengthsV1Marker>
+ DataProvider<RocDateLengthsV1Marker>
+ ?Sized,
{
let req = DataRequest {
locale,
metadata: Default::default(),
};
let payload = match kind {
AnyCalendarKind::Buddhist => {
DataProvider::<<Buddhist as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Chinese => {
DataProvider::<<Chinese as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Coptic => {
DataProvider::<<Coptic as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Dangi => {
DataProvider::<<Dangi as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Ethiopian => {
DataProvider::<<Ethiopian as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::EthiopianAmeteAlem => {
DataProvider::<<Ethiopian as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Gregorian => {
DataProvider::<<Gregorian as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Hebrew => {
DataProvider::<<Hebrew as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Indian => {
DataProvider::<<Indian as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::IslamicCivil => DataProvider::<
<IslamicCivil as CldrCalendar>::DateLengthsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::IslamicObservational => DataProvider::<
<IslamicObservational as CldrCalendar>::DateLengthsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::IslamicTabular => DataProvider::<
<IslamicTabular as CldrCalendar>::DateLengthsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::IslamicUmmAlQura => DataProvider::<
<IslamicUmmAlQura as CldrCalendar>::DateLengthsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::Japanese => {
DataProvider::<<Japanese as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::JapaneseExtended => DataProvider::<
<JapaneseExtended as CldrCalendar>::DateLengthsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::Persian => {
DataProvider::<<Persian as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Roc => {
DataProvider::<<Roc as CldrCalendar>::DateLengthsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
_ => {
return Err(
DataError::custom("Don't know how to load data for specified calendar")
.with_debug_context(&kind),
)
}
};
Ok(payload)
}
pub(crate) fn load_symbols_for_any_calendar_kind<P>(
provider: &P,
locale: &DataLocale,
kind: AnyCalendarKind,
) -> Result<DataPayload<ErasedDateSymbolsV1Marker>, DataError>
where
P: DataProvider<BuddhistDateSymbolsV1Marker>
+ DataProvider<ChineseDateSymbolsV1Marker>
+ DataProvider<CopticDateSymbolsV1Marker>
+ DataProvider<DangiDateSymbolsV1Marker>
+ DataProvider<EthiopianDateSymbolsV1Marker>
+ DataProvider<GregorianDateSymbolsV1Marker>
+ DataProvider<HebrewDateSymbolsV1Marker>
+ DataProvider<IndianDateSymbolsV1Marker>
+ DataProvider<IslamicDateSymbolsV1Marker>
+ DataProvider<JapaneseDateSymbolsV1Marker>
+ DataProvider<JapaneseExtendedDateSymbolsV1Marker>
+ DataProvider<PersianDateSymbolsV1Marker>
+ DataProvider<RocDateSymbolsV1Marker>
+ ?Sized,
{
let req = DataRequest {
locale,
metadata: Default::default(),
};
let payload = match kind {
AnyCalendarKind::Buddhist => {
DataProvider::<<Buddhist as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Chinese => {
DataProvider::<<Chinese as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Coptic => {
DataProvider::<<Coptic as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Dangi => {
DataProvider::<<Dangi as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Ethiopian => {
DataProvider::<<Ethiopian as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::EthiopianAmeteAlem => {
DataProvider::<<Ethiopian as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Gregorian => {
DataProvider::<<Gregorian as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Hebrew => {
DataProvider::<<Hebrew as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Indian => {
DataProvider::<<Indian as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::IslamicCivil => DataProvider::<
<IslamicCivil as CldrCalendar>::DateSymbolsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::IslamicObservational => DataProvider::<
<IslamicObservational as CldrCalendar>::DateSymbolsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::IslamicTabular => DataProvider::<
<IslamicTabular as CldrCalendar>::DateSymbolsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::IslamicUmmAlQura => DataProvider::<
<IslamicUmmAlQura as CldrCalendar>::DateSymbolsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::Japanese => {
DataProvider::<<Japanese as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::JapaneseExtended => DataProvider::<
<JapaneseExtended as CldrCalendar>::DateSymbolsV1Marker,
>::load(provider, req)?
.take_payload()?
.cast(),
AnyCalendarKind::Persian => {
DataProvider::<<Persian as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
AnyCalendarKind::Roc => {
DataProvider::<<Roc as CldrCalendar>::DateSymbolsV1Marker>::load(provider, req)?
.take_payload()?
.cast()
}
_ => {
return Err(
DataError::custom("Don't know how to load data for specified calendar")
.with_debug_context(&kind),
)
}
};
Ok(payload)
}
#[cfg(any(feature = "datagen", feature = "experimental"))]
mod private {
pub trait Sealed {}
}
#[cfg(any(feature = "datagen", feature = "experimental"))]
pub trait CalMarkers<M>: private::Sealed
where
M: DataMarker,
{
type Buddhist: KeyedDataMarker<Yokeable = M::Yokeable>;
type Chinese: KeyedDataMarker<Yokeable = M::Yokeable>;
type Coptic: KeyedDataMarker<Yokeable = M::Yokeable>;
type Dangi: KeyedDataMarker<Yokeable = M::Yokeable>;
type Ethiopian: KeyedDataMarker<Yokeable = M::Yokeable>;
type EthiopianAmeteAlem: KeyedDataMarker<Yokeable = M::Yokeable>;
type Gregorian: KeyedDataMarker<Yokeable = M::Yokeable>;
type Hebrew: KeyedDataMarker<Yokeable = M::Yokeable>;
type Indian: KeyedDataMarker<Yokeable = M::Yokeable>;
type IslamicCivil: KeyedDataMarker<Yokeable = M::Yokeable>;
type IslamicObservational: KeyedDataMarker<Yokeable = M::Yokeable>;
type IslamicTabular: KeyedDataMarker<Yokeable = M::Yokeable>;
type IslamicUmmAlQura: KeyedDataMarker<Yokeable = M::Yokeable>;
type Japanese: KeyedDataMarker<Yokeable = M::Yokeable>;
type JapaneseExtended: KeyedDataMarker<Yokeable = M::Yokeable>;
type Persian: KeyedDataMarker<Yokeable = M::Yokeable>;
type Roc: KeyedDataMarker<Yokeable = M::Yokeable>;
}
#[derive(Debug)]
#[cfg(any(feature = "datagen", feature = "experimental"))]
#[allow(clippy::exhaustive_enums)] pub enum FullDataCalMarkers {}
#[cfg(any(feature = "datagen", feature = "experimental"))]
impl private::Sealed for FullDataCalMarkers {}
#[derive(Debug)]
#[cfg(any(feature = "datagen", feature = "experimental"))]
#[allow(clippy::exhaustive_enums)] pub enum NoDataCalMarkers {}
#[cfg(any(feature = "datagen", feature = "experimental"))]
impl private::Sealed for NoDataCalMarkers {}
#[cfg(any(feature = "datagen", feature = "experimental"))]
impl<M> CalMarkers<M> for NoDataCalMarkers
where
M: DataMarker,
{
type Buddhist = NeverMarker<M::Yokeable>;
type Chinese = NeverMarker<M::Yokeable>;
type Coptic = NeverMarker<M::Yokeable>;
type Dangi = NeverMarker<M::Yokeable>;
type Ethiopian = NeverMarker<M::Yokeable>;
type EthiopianAmeteAlem = NeverMarker<M::Yokeable>;
type Gregorian = NeverMarker<M::Yokeable>;
type Hebrew = NeverMarker<M::Yokeable>;
type Indian = NeverMarker<M::Yokeable>;
type IslamicCivil = NeverMarker<M::Yokeable>;
type IslamicObservational = NeverMarker<M::Yokeable>;
type IslamicTabular = NeverMarker<M::Yokeable>;
type IslamicUmmAlQura = NeverMarker<M::Yokeable>;
type Japanese = NeverMarker<M::Yokeable>;
type JapaneseExtended = NeverMarker<M::Yokeable>;
type Persian = NeverMarker<M::Yokeable>;
type Roc = NeverMarker<M::Yokeable>;
}
#[cfg(feature = "experimental")]
pub(crate) struct AnyCalendarProvider<H, P> {
provider: P,
kind: AnyCalendarKind,
_helper: PhantomData<H>,
}
#[cfg(feature = "experimental")]
impl<H, P> AnyCalendarProvider<H, P> {
pub(crate) fn new(provider: P, kind: AnyCalendarKind) -> Self {
Self {
provider,
kind,
_helper: PhantomData,
}
}
}
#[cfg(feature = "experimental")]
impl<M, H, P> BoundDataProvider<M> for AnyCalendarProvider<H, P>
where
M: DataMarker,
H: CalMarkers<M>,
P: Sized
+ DataProvider<H::Buddhist>
+ DataProvider<H::Chinese>
+ DataProvider<H::Coptic>
+ DataProvider<H::Dangi>
+ DataProvider<H::Ethiopian>
+ DataProvider<H::EthiopianAmeteAlem>
+ DataProvider<H::Gregorian>
+ DataProvider<H::Hebrew>
+ DataProvider<H::Indian>
+ DataProvider<H::IslamicCivil>
+ DataProvider<H::IslamicObservational>
+ DataProvider<H::IslamicTabular>
+ DataProvider<H::IslamicUmmAlQura>
+ DataProvider<H::Japanese>
+ DataProvider<H::JapaneseExtended>
+ DataProvider<H::Persian>
+ DataProvider<H::Roc>,
{
fn load_bound(&self, req: DataRequest) -> Result<DataResponse<M>, DataError> {
use AnyCalendarKind::*;
let p = &self.provider;
match self.kind {
Buddhist => H::Buddhist::bind(p).load_bound(req),
Chinese => H::Chinese::bind(p).load_bound(req),
Coptic => H::Coptic::bind(p).load_bound(req),
Dangi => H::Dangi::bind(p).load_bound(req),
Ethiopian => H::Ethiopian::bind(p).load_bound(req),
EthiopianAmeteAlem => H::EthiopianAmeteAlem::bind(p).load_bound(req),
Gregorian => H::Gregorian::bind(p).load_bound(req),
Hebrew => H::Hebrew::bind(p).load_bound(req),
Indian => H::Indian::bind(p).load_bound(req),
IslamicCivil => H::IslamicCivil::bind(p).load_bound(req),
IslamicObservational => H::IslamicObservational::bind(p).load_bound(req),
IslamicTabular => H::IslamicTabular::bind(p).load_bound(req),
IslamicUmmAlQura => H::IslamicUmmAlQura::bind(p).load_bound(req),
Japanese => H::Japanese::bind(p).load_bound(req),
JapaneseExtended => H::JapaneseExtended::bind(p).load_bound(req),
Persian => H::Persian::bind(p).load_bound(req),
Roc => H::Roc::bind(p).load_bound(req),
_ => Err(
DataError::custom("Don't know how to load data for specified calendar")
.with_debug_context(&self.kind),
),
}
}
fn bound_key(&self) -> DataKey {
use AnyCalendarKind::*;
match self.kind {
Buddhist => H::Buddhist::KEY,
Chinese => H::Chinese::KEY,
Coptic => H::Coptic::KEY,
Dangi => H::Dangi::KEY,
Ethiopian => H::Ethiopian::KEY,
EthiopianAmeteAlem => H::EthiopianAmeteAlem::KEY,
Gregorian => H::Gregorian::KEY,
Hebrew => H::Hebrew::KEY,
Indian => H::Indian::KEY,
IslamicCivil => H::IslamicCivil::KEY,
IslamicObservational => H::IslamicObservational::KEY,
IslamicTabular => H::IslamicTabular::KEY,
IslamicUmmAlQura => H::IslamicUmmAlQura::KEY,
Japanese => H::Japanese::KEY,
JapaneseExtended => H::JapaneseExtended::KEY,
Persian => H::Persian::KEY,
Roc => H::Roc::KEY,
_ => NeverMarker::<M::Yokeable>::KEY,
}
}
}
#[cfg(any(feature = "datagen", feature = "experimental"))]
macro_rules! impl_load_any_calendar {
([$(($erased:ident, $marker:ident)),+], [$($kind_cal:ident),+], [$($kind:ident => $cal:ident),+]) => {
impl_load_any_calendar!(@expand [$(($erased, $marker)),+], [$($kind_cal),+], [$($kind => $cal),+]);
};
(@expand [$(($erased:ident, $marker:ident)),+], $tail1:tt, $tail2:tt) => {
$(impl_load_any_calendar!(@single_impl $erased, $marker, $tail1, $tail2);)+
};
(@single_impl $erased:ident, $marker:ident, [$($kind_cal:ident),+], [$($kind:ident => $cal:ident),+]) => {
impl CalMarkers<$erased> for FullDataCalMarkers {
$(
type $kind_cal = <$kind_cal as CldrCalendar>::$marker;
)+
$(
type $kind = <$cal as CldrCalendar>::$marker;
)+
}
};
}
#[cfg(any(feature = "datagen", feature = "experimental"))]
impl_load_any_calendar!([
(DatePatternV1Marker, DatePatternV1Marker),
(YearNamesV1Marker, YearNamesV1Marker),
(MonthNamesV1Marker, MonthNamesV1Marker),
(SkeletaV1Marker, SkeletaV1Marker)
], [
Buddhist,
Chinese,
Coptic,
Dangi,
Ethiopian,
Gregorian,
Hebrew,
Indian,
IslamicCivil,
IslamicObservational,
IslamicTabular,
IslamicUmmAlQura,
Japanese,
JapaneseExtended,
Persian,
Roc
], [
EthiopianAmeteAlem => Ethiopian
]);
pub(crate) fn convert_if_necessary<'a>(
any_calendar: &'a AnyCalendar,
value: &impl crate::input::DateInput<Calendar = AnyCalendar>,
) -> Result<
Option<icu_calendar::Date<icu_calendar::Ref<'a, AnyCalendar>>>,
crate::MismatchedCalendarError,
> {
let this_kind = any_calendar.kind();
let date_kind = value.any_calendar_kind();
if Some(this_kind) != date_kind {
if date_kind != Some(AnyCalendarKind::Iso) {
return Err(crate::MismatchedCalendarError {
this_kind,
date_kind,
});
}
let date = value.to_iso().to_any();
let converted = any_calendar.convert_any_date(&date);
Ok(Some(converted))
} else {
Ok(None)
}
}
pub(crate) fn convert_datetime_if_necessary<'a>(
any_calendar: &'a AnyCalendar,
value: &impl crate::input::DateTimeInput<Calendar = AnyCalendar>,
) -> Result<
Option<icu_calendar::DateTime<icu_calendar::Ref<'a, AnyCalendar>>>,
crate::MismatchedCalendarError,
> {
let this_kind = any_calendar.kind();
let date_kind = value.any_calendar_kind();
if Some(this_kind) != date_kind {
if date_kind != Some(AnyCalendarKind::Iso) {
return Err(crate::MismatchedCalendarError {
this_kind,
date_kind,
});
}
let date = value.to_iso();
let time = icu_calendar::Time::new(
value.hour().unwrap_or_default(),
value.minute().unwrap_or_default(),
value.second().unwrap_or_default(),
value.nanosecond().unwrap_or_default(),
);
let datetime = icu_calendar::DateTime::new(date, time).to_any();
let converted = any_calendar.convert_any_datetime(&datetime);
Ok(Some(converted))
} else {
Ok(None)
}
}