Skip to content

Commit

Permalink
More FSet renames; GetField; rm NeverCalendar (#5686)
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc authored Oct 15, 2024
1 parent e1bc5b4 commit eaacd10
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 322 deletions.
12 changes: 2 additions & 10 deletions components/datetime/src/calendar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,7 @@ pub trait CldrCalendar: InternalCldrCalendar {
type SkeletaV1Marker: DataMarker<DataStruct = PackedPatternsV1<'static>>;
}

/// A calendar that can never exist.
///
/// Used as a substitute for calendar parameters when a calendar is not needed,
/// such as in a time formatter.
#[derive(Debug)]
#[allow(clippy::exhaustive_enums)] // empty enum
pub enum NeverCalendar {}

impl CldrCalendar for NeverCalendar {
impl CldrCalendar for () {
type YearNamesV1Marker = NeverMarker<YearNamesV1<'static>>;
type MonthNamesV1Marker = NeverMarker<MonthNamesV1<'static>>;
type SkeletaV1Marker = NeverMarker<PackedPatternsV1<'static>>;
Expand Down Expand Up @@ -163,7 +155,7 @@ impl CldrCalendar for Roc {
type SkeletaV1Marker = RocDateNeoSkeletonPatternsV1Marker;
}

impl InternalCldrCalendar for NeverCalendar {}
impl InternalCldrCalendar for () {}
impl InternalCldrCalendar for Buddhist {}
impl InternalCldrCalendar for Chinese {}
impl InternalCldrCalendar for Coptic {}
Expand Down
37 changes: 18 additions & 19 deletions components/datetime/src/format/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::helpers::size_test;
use crate::input;
use crate::input::ExtractedInput;
use crate::neo_marker::{
AllInputMarkers, DateInputMarkers, DateTimeMarkers, IsInCalendar, NeoGetField, NeoNeverMarker,
AllInputMarkers, DateInputMarkers, DateTimeMarkers, GetField, IsInCalendar, NeoNeverMarker,
NeverField, TimeMarkers, TypedDateDataMarkers, ZoneMarkers,
};
use crate::neo_pattern::{DateTimePattern, DateTimePatternBorrowed};
Expand Down Expand Up @@ -1413,15 +1413,14 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// ```
/// use icu::calendar::Time;
/// use icu::datetime::neo_pattern::DateTimePattern;
/// use icu::datetime::NeverCalendar;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::datetime::neo_skeleton::NeoTimeSkeleton;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let locale = &locale!("bn").into();
///
/// let mut names = TypedDateTimeNames::<NeverCalendar, NeoTimeSkeleton>::try_new(&locale).unwrap();
/// let mut names = TypedDateTimeNames::<(), NeoTimeSkeleton>::try_new(&locale).unwrap();
/// names.include_fixed_decimal_formatter();
///
/// // Create a pattern for the time, which is all numbers
Expand Down Expand Up @@ -2270,12 +2269,12 @@ where
where
I: ?Sized
+ IsInCalendar<C>
+ NeoGetField<<R::D as DateInputMarkers>::YearInput>
+ NeoGetField<<R::D as DateInputMarkers>::MonthInput>
+ NeoGetField<<R::D as DateInputMarkers>::DayOfMonthInput>
+ NeoGetField<<R::D as DateInputMarkers>::DayOfWeekInput>
+ NeoGetField<<R::D as DateInputMarkers>::AnyCalendarKindInput>
+ NeoGetField<NeverField>,
+ GetField<<R::D as DateInputMarkers>::YearInput>
+ GetField<<R::D as DateInputMarkers>::MonthInput>
+ GetField<<R::D as DateInputMarkers>::DayOfMonthInput>
+ GetField<<R::D as DateInputMarkers>::DayOfWeekInput>
+ GetField<<R::D as DateInputMarkers>::AnyCalendarKindInput>
+ GetField<NeverField>,
{
FormattedDateTimePattern {
pattern: self.inner.pattern,
Expand Down Expand Up @@ -2336,11 +2335,11 @@ where
where
I: ?Sized
+ IsInCalendar<C>
+ NeoGetField<<R::T as TimeMarkers>::HourInput>
+ NeoGetField<<R::T as TimeMarkers>::MinuteInput>
+ NeoGetField<<R::T as TimeMarkers>::SecondInput>
+ NeoGetField<<R::T as TimeMarkers>::NanoSecondInput>
+ NeoGetField<NeverField>,
+ GetField<<R::T as TimeMarkers>::HourInput>
+ GetField<<R::T as TimeMarkers>::MinuteInput>
+ GetField<<R::T as TimeMarkers>::SecondInput>
+ GetField<<R::T as TimeMarkers>::NanoSecondInput>
+ GetField<NeverField>,
{
FormattedDateTimePattern {
pattern: self.inner.pattern,
Expand Down Expand Up @@ -2401,11 +2400,11 @@ where
where
I: ?Sized
+ IsInCalendar<C>
+ NeoGetField<<R::Z as ZoneMarkers>::TimeZoneOffsetInput>
+ NeoGetField<<R::Z as ZoneMarkers>::TimeZoneIdInput>
+ NeoGetField<<R::Z as ZoneMarkers>::TimeZoneMetazoneInput>
+ NeoGetField<<R::Z as ZoneMarkers>::TimeZoneVariantInput>
+ NeoGetField<NeverField>,
+ GetField<<R::Z as ZoneMarkers>::TimeZoneOffsetInput>
+ GetField<<R::Z as ZoneMarkers>::TimeZoneIdInput>
+ GetField<<R::Z as ZoneMarkers>::TimeZoneMetazoneInput>
+ GetField<<R::Z as ZoneMarkers>::TimeZoneVariantInput>
+ GetField<NeverField>,
{
FormattedDateTimePattern {
pattern: self.inner.pattern,
Expand Down
54 changes: 27 additions & 27 deletions components/datetime/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! A collection of utilities for representing and working with dates as an input to
//! formatting operations.
use crate::neo_marker::{DateInputMarkers, NeoGetField, TimeMarkers, ZoneMarkers};
use crate::neo_marker::{DateInputMarkers, GetField, TimeMarkers, ZoneMarkers};
use crate::provider::time_zones::{MetazoneId, TimeZoneBcp47Id};
use icu_calendar::any_calendar::AnyCalendarKind;
use icu_timezone::{UtcOffset, ZoneVariant};
Expand Down Expand Up @@ -40,34 +40,34 @@ impl ExtractedInput {
T: TimeMarkers,
Z: ZoneMarkers,
I: ?Sized
+ NeoGetField<D::YearInput>
+ NeoGetField<D::MonthInput>
+ NeoGetField<D::DayOfMonthInput>
+ NeoGetField<D::DayOfWeekInput>
+ NeoGetField<D::AnyCalendarKindInput>
+ NeoGetField<T::HourInput>
+ NeoGetField<T::MinuteInput>
+ NeoGetField<T::SecondInput>
+ NeoGetField<T::NanoSecondInput>
+ NeoGetField<Z::TimeZoneOffsetInput>
+ NeoGetField<Z::TimeZoneIdInput>
+ NeoGetField<Z::TimeZoneMetazoneInput>
+ NeoGetField<Z::TimeZoneVariantInput>,
+ GetField<D::YearInput>
+ GetField<D::MonthInput>
+ GetField<D::DayOfMonthInput>
+ GetField<D::DayOfWeekInput>
+ GetField<D::AnyCalendarKindInput>
+ GetField<T::HourInput>
+ GetField<T::MinuteInput>
+ GetField<T::SecondInput>
+ GetField<T::NanoSecondInput>
+ GetField<Z::TimeZoneOffsetInput>
+ GetField<Z::TimeZoneIdInput>
+ GetField<Z::TimeZoneMetazoneInput>
+ GetField<Z::TimeZoneVariantInput>,
{
Self {
year: NeoGetField::<D::YearInput>::get_field(input).into(),
month: NeoGetField::<D::MonthInput>::get_field(input).into(),
day_of_month: NeoGetField::<D::DayOfMonthInput>::get_field(input).into(),
iso_weekday: NeoGetField::<D::DayOfWeekInput>::get_field(input).into(),
any_calendar_kind: NeoGetField::<D::AnyCalendarKindInput>::get_field(input).into(),
hour: NeoGetField::<T::HourInput>::get_field(input).into(),
minute: NeoGetField::<T::MinuteInput>::get_field(input).into(),
second: NeoGetField::<T::SecondInput>::get_field(input).into(),
nanosecond: NeoGetField::<T::NanoSecondInput>::get_field(input).into(),
offset: NeoGetField::<Z::TimeZoneOffsetInput>::get_field(input).into(),
time_zone_id: NeoGetField::<Z::TimeZoneIdInput>::get_field(input).into(),
metazone_id: NeoGetField::<Z::TimeZoneMetazoneInput>::get_field(input).into(),
zone_variant: NeoGetField::<Z::TimeZoneVariantInput>::get_field(input).into(),
year: GetField::<D::YearInput>::get_field(input).into(),
month: GetField::<D::MonthInput>::get_field(input).into(),
day_of_month: GetField::<D::DayOfMonthInput>::get_field(input).into(),
iso_weekday: GetField::<D::DayOfWeekInput>::get_field(input).into(),
any_calendar_kind: GetField::<D::AnyCalendarKindInput>::get_field(input).into(),
hour: GetField::<T::HourInput>::get_field(input).into(),
minute: GetField::<T::MinuteInput>::get_field(input).into(),
second: GetField::<T::SecondInput>::get_field(input).into(),
nanosecond: GetField::<T::NanoSecondInput>::get_field(input).into(),
offset: GetField::<Z::TimeZoneOffsetInput>::get_field(input).into(),
time_zone_id: GetField::<Z::TimeZoneIdInput>::get_field(input).into(),
metazone_id: GetField::<Z::TimeZoneMetazoneInput>::get_field(input).into(),
zone_variant: GetField::<Z::TimeZoneVariantInput>::get_field(input).into(),
}
}
}
2 changes: 1 addition & 1 deletion components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod time_zone;
mod tz_registry;

pub use calendar::CldrCalendar;
pub use calendar::{InternalCldrCalendar, NeverCalendar};
pub use calendar::InternalCldrCalendar;
pub use error::MismatchedCalendarError;
pub use format::datetime::DateTimeWriteError;
pub use format::neo::{FormattedDateTimePattern, LoadError, SingleLoadError, TypedDateTimeNames};
Expand Down
Loading

0 comments on commit eaacd10

Please sign in to comment.