diff --git a/components/datetime/src/format/neo.rs b/components/datetime/src/format/neo.rs index e42a1dbf5c..3200a18d46 100644 --- a/components/datetime/src/format/neo.rs +++ b/components/datetime/src/format/neo.rs @@ -7,7 +7,6 @@ use super::{ GetNameForDayPeriodError, GetNameForMonthError, GetNameForWeekdayError, GetSymbolForEraError, MonthPlaceholderValue, }; -use crate::calendar::CldrCalendar; use crate::external_loaders::*; use crate::fields::{self, Field, FieldLength, FieldSymbol}; use crate::helpers::size_test; @@ -22,6 +21,7 @@ use crate::neo_skeleton::NeoDateTimeSkeleton; use crate::pattern::PatternItem; use crate::provider::neo::*; use crate::provider::time_zones::tz; +use crate::scaffold::*; use crate::time_zone::ResolvedNeoTimeZoneSkeleton; use crate::time_zone::TimeZoneDataPayloadsBorrowed; use core::fmt; diff --git a/components/datetime/src/lib.rs b/components/datetime/src/lib.rs index 542f664467..179793d16d 100644 --- a/components/datetime/src/lib.rs +++ b/components/datetime/src/lib.rs @@ -89,7 +89,6 @@ extern crate alloc; -mod calendar; mod error; mod external_loaders; pub mod fields; @@ -108,6 +107,7 @@ pub mod options; pub mod pattern; pub mod provider; pub(crate) mod raw; +pub mod scaffold; #[doc(hidden)] #[allow(clippy::exhaustive_structs, clippy::exhaustive_enums)] // private-ish module #[cfg(feature = "datagen")] @@ -115,8 +115,6 @@ pub mod skeleton; mod time_zone; mod tz_registry; -pub use calendar::CldrCalendar; -pub use calendar::InternalCldrCalendar; pub use error::MismatchedCalendarError; pub use format::datetime::DateTimeWriteError; pub use format::neo::{FormattedDateTimePattern, LoadError, SingleLoadError, TypedDateTimeNames}; diff --git a/components/datetime/src/neo.rs b/components/datetime/src/neo.rs index 58bd43014b..9c4323af66 100644 --- a/components/datetime/src/neo.rs +++ b/components/datetime/src/neo.rs @@ -4,7 +4,6 @@ //! High-level entrypoints for Neo DateTime Formatter -use crate::calendar::AnyCalendarProvider; use crate::external_loaders::*; use crate::format::datetime::try_write_pattern_items; use crate::format::datetime::DateTimeWriteError; @@ -13,7 +12,7 @@ use crate::input::ExtractedInput; use crate::neo_marker::DateInputMarkers; use crate::neo_marker::HasConstComponents; use crate::neo_marker::{ - AllInputMarkers, CalMarkers, ConvertCalendar, DateDataMarkers, DateTimeMarkers, GetField, + AllInputMarkers, ConvertCalendar, DateDataMarkers, DateTimeMarkers, GetField, IsAnyCalendarKind, IsInCalendar, IsRuntimeComponents, TimeMarkers, TypedDateDataMarkers, ZoneMarkers, }; @@ -23,7 +22,7 @@ use crate::options::preferences::HourCycle; use crate::provider::neo::*; use crate::provider::ErasedPackedPatterns; use crate::raw::neo::*; -use crate::CldrCalendar; +use crate::scaffold::*; use crate::MismatchedCalendarError; use core::fmt; use core::marker::PhantomData; diff --git a/components/datetime/src/neo_marker.rs b/components/datetime/src/neo_marker.rs index 1fb3c6b906..a3a88ca38d 100644 --- a/components/datetime/src/neo_marker.rs +++ b/components/datetime/src/neo_marker.rs @@ -341,7 +341,7 @@ use crate::{ format::neo::*, neo_skeleton::*, provider::{neo::*, time_zones::tz, *}, - CldrCalendar, + scaffold::*, }; use icu_calendar::{ any_calendar::IntoAnyCalendar, @@ -356,18 +356,6 @@ use icu_timezone::{ CustomTimeZone, CustomZonedDateTime, MetazoneId, TimeZoneBcp47Id, UtcOffset, ZoneVariant, }; -// TODO: Figure out where to export these traits -#[doc(inline)] -pub use crate::calendar::CalMarkers; -#[doc(inline)] -pub use crate::calendar::FullDataCalMarkers; -#[doc(inline)] -pub use crate::calendar::NoDataCalMarkers; - -pub(crate) mod private { - pub trait Sealed {} -} - /// A type that can be converted into a specific calendar system. pub trait ConvertCalendar { /// The converted type. This can be the same as the receiver type. @@ -993,7 +981,7 @@ pub trait HasConstZoneComponent { /// A trait associating types for date formatting in any calendar /// (input types only). -pub trait DateInputMarkers: private::Sealed { +pub trait DateInputMarkers: UnstableSealed { /// Marker for resolving the year input field. type YearInput: Into>; /// Marker for resolving the month input field. @@ -1008,7 +996,7 @@ pub trait DateInputMarkers: private::Sealed { /// A trait associating types for date formatting in a specific calendar /// (data markers only). -pub trait TypedDateDataMarkers: private::Sealed { +pub trait TypedDateDataMarkers: UnstableSealed { /// Marker for loading date skeleton patterns. type DateSkeletonPatternsV1Marker: DataMarker>; /// Marker for loading year names. @@ -1021,7 +1009,7 @@ pub trait TypedDateDataMarkers: private::Sealed { /// A trait associating types for date formatting in any calendar /// (data markers only). -pub trait DateDataMarkers: private::Sealed { +pub trait DateDataMarkers: UnstableSealed { /// Cross-calendar data markers for date skeleta. type Skel: CalMarkers; /// Cross-calendar data markers for year names. @@ -1034,7 +1022,7 @@ pub trait DateDataMarkers: private::Sealed { /// A trait associating types for time formatting /// (input types and data markers). -pub trait TimeMarkers: private::Sealed { +pub trait TimeMarkers: UnstableSealed { /// Marker for resolving the day-of-month input field. type HourInput: Into>; /// Marker for resolving the day-of-week input field. @@ -1051,7 +1039,7 @@ pub trait TimeMarkers: private::Sealed { /// A trait associating types for time zone formatting /// (input types and data markers). -pub trait ZoneMarkers: private::Sealed { +pub trait ZoneMarkers: UnstableSealed { /// Marker for resolving the time zone offset input field. type TimeZoneOffsetInput: Into>; /// Marker for resolving the time zone id input field. @@ -1076,7 +1064,7 @@ pub trait ZoneMarkers: private::Sealed { /// A trait associating constants and types implementing various other traits /// required for datetime formatting. -pub trait DateTimeMarkers: private::Sealed + DateTimeNamesMarker { +pub trait DateTimeMarkers: UnstableSealed + DateTimeNamesMarker { /// Associated types for date formatting. /// /// Should implement [`DateDataMarkers`], [`TypedDateDataMarkers`], and [`DateInputMarkers`]. @@ -1150,7 +1138,7 @@ where #[allow(clippy::exhaustive_enums)] // empty marker enum pub enum NeoNeverMarker {} -impl private::Sealed for NeoNeverMarker {} +impl UnstableSealed for NeoNeverMarker {} impl DateInputMarkers for NeoNeverMarker { type YearInput = NeverField; @@ -1215,7 +1203,7 @@ pub struct DateTimeCombo { pub fractional_second_digits: Option, } -impl private::Sealed for DateTimeCombo {} +impl UnstableSealed for DateTimeCombo {} impl DateTimeCombo { /// Creates a date/time/zone skeleton with the given formatting length. @@ -1833,7 +1821,7 @@ macro_rules! impl_date_or_calendar_period_marker { $(alignment: $option_alignment_yes,)? $(year_style: $year_yes,)? ); - impl private::Sealed for $type {} + impl UnstableSealed for $type {} impl DateTimeNamesMarker for $type { type YearNames = datetime_marker_helper!(@names/year, $($years_yes)?); type MonthNames = datetime_marker_helper!(@names/month, $($months_yes)?); @@ -2057,7 +2045,7 @@ macro_rules! impl_time_marker { alignment: yes, $(fractional_second_digits: $nanosecond_yes,)? ); - impl private::Sealed for $type {} + impl UnstableSealed for $type {} impl DateTimeNamesMarker for $type { type YearNames = datetime_marker_helper!(@names/year,); type MonthNames = datetime_marker_helper!(@names/month,); @@ -2202,7 +2190,7 @@ macro_rules! impl_zone_marker { $type, sample_length: $sample_length, ); - impl private::Sealed for $type {} + impl UnstableSealed for $type {} impl DateTimeNamesMarker for $type { type YearNames = datetime_marker_helper!(@names/year,); type MonthNames = datetime_marker_helper!(@names/month,); @@ -2742,7 +2730,7 @@ impl_zoneddatetime_marker!( ); /// Trait for components that can be formatted at runtime. -pub trait IsRuntimeComponents: private::Sealed + GetField {} +pub trait IsRuntimeComponents: UnstableSealed + GetField {} impl GetField for NeoDateSkeleton { fn get_field(&self) -> NeoComponents { @@ -2750,7 +2738,7 @@ impl GetField for NeoDateSkeleton { } } -impl private::Sealed for NeoDateSkeleton {} +impl UnstableSealed for NeoDateSkeleton {} impl IsRuntimeComponents for NeoDateSkeleton {} @@ -2805,7 +2793,7 @@ impl_get_field!(NeoDateSkeleton, length, yes); impl_get_field!(NeoDateSkeleton, alignment, yes); impl_get_field!(NeoDateSkeleton, year_style, yes); -impl private::Sealed for NeoCalendarPeriodSkeleton {} +impl UnstableSealed for NeoCalendarPeriodSkeleton {} impl GetField for NeoCalendarPeriodSkeleton { fn get_field(&self) -> NeoComponents { @@ -2866,7 +2854,7 @@ impl_get_field!(NeoCalendarPeriodSkeleton, length, yes); impl_get_field!(NeoCalendarPeriodSkeleton, alignment, yes); impl_get_field!(NeoCalendarPeriodSkeleton, year_style, yes); -impl private::Sealed for NeoTimeSkeleton {} +impl UnstableSealed for NeoTimeSkeleton {} impl GetField for NeoTimeSkeleton { fn get_field(&self) -> NeoComponents { @@ -2914,7 +2902,7 @@ impl_get_field!(NeoTimeSkeleton, length, yes); impl_get_field!(NeoTimeSkeleton, alignment, yes); impl_get_field!(NeoTimeSkeleton, fractional_second_digits, yes); -impl private::Sealed for NeoTimeZoneSkeleton {} +impl UnstableSealed for NeoTimeZoneSkeleton {} impl GetField for NeoTimeZoneSkeleton { fn get_field(&self) -> NeoComponents { @@ -2964,7 +2952,7 @@ impl DateTimeMarkers for NeoTimeZoneSkeleton { impl_get_field!(NeoTimeZoneSkeleton, never); impl_get_field!(NeoTimeZoneSkeleton, length, yes); -impl private::Sealed for NeoDateTimeSkeleton {} +impl UnstableSealed for NeoDateTimeSkeleton {} impl GetField for NeoDateTimeSkeleton { fn get_field(&self) -> NeoComponents { @@ -3004,7 +2992,7 @@ impl_get_field!(NeoDateTimeSkeleton, alignment, yes); impl_get_field!(NeoDateTimeSkeleton, year_style, yes); impl_get_field!(NeoDateTimeSkeleton, fractional_second_digits, yes); -impl private::Sealed for NeoSkeleton {} +impl UnstableSealed for NeoSkeleton {} impl GetField for NeoSkeleton { fn get_field(&self) -> NeoComponents { diff --git a/components/datetime/src/calendar.rs b/components/datetime/src/scaffold/calendar.rs similarity index 89% rename from components/datetime/src/calendar.rs rename to components/datetime/src/scaffold/calendar.rs index 153ac3170f..ab4cac1fb8 100644 --- a/components/datetime/src/calendar.rs +++ b/components/datetime/src/scaffold/calendar.rs @@ -2,6 +2,8 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). +//! Scaffolding traits and impls for calendars. + use icu_calendar::any_calendar::AnyCalendarKind; use icu_calendar::chinese::Chinese; use icu_calendar::roc::Roc; @@ -14,22 +16,10 @@ use icu_calendar::{ use icu_provider::prelude::*; use crate::provider::{neo::*, *}; +use crate::scaffold::UnstableSealed; use core::marker::PhantomData; use icu_provider::marker::NeverMarker; -/// Internal-ish trait for sealing `CldrCalendar`. -/// -/// The `CldrCalendar` trait is sealed except when the `"experimental"` Cargo -/// feature is enabled. If implementing `CldrCalendar`, you must also -/// implement `UnstableCldrCalendar` and acknowledge the stability policy. -/// -///
-/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, -/// including in SemVer minor releases. Do not implement this trait in userland. -///
-// TODO(#4338): Decide what to do with this when we retire this crate's "experimental" feature. -pub trait InternalCldrCalendar {} - /// A calendar that can be found in CLDR /// /// New implementors of this trait will likely also wish to modify `get_era_code_map()` @@ -39,7 +29,7 @@ pub trait InternalCldrCalendar {} /// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, /// including in SemVer minor releases. Do not implement this trait in userland. /// -pub trait CldrCalendar: InternalCldrCalendar { +pub trait CldrCalendar: UnstableSealed { /// The data marker for loading year symbols for this calendar. type YearNamesV1Marker: DataMarker>; @@ -155,27 +145,23 @@ impl CldrCalendar for Roc { type SkeletaV1Marker = RocDateNeoSkeletonPatternsV1Marker; } -impl InternalCldrCalendar for () {} -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 {} - -mod private { - pub trait Sealed {} -} +impl UnstableSealed for () {} +impl UnstableSealed for Buddhist {} +impl UnstableSealed for Chinese {} +impl UnstableSealed for Coptic {} +impl UnstableSealed for Dangi {} +impl UnstableSealed for Ethiopian {} +impl UnstableSealed for Gregorian {} +impl UnstableSealed for Hebrew {} +impl UnstableSealed for Indian {} +impl UnstableSealed for IslamicCivil {} +impl UnstableSealed for IslamicObservational {} +impl UnstableSealed for IslamicTabular {} +impl UnstableSealed for IslamicUmmAlQura {} +impl UnstableSealed for Japanese {} +impl UnstableSealed for JapaneseExtended {} +impl UnstableSealed for Persian {} +impl UnstableSealed for Roc {} /// A collection of marker types associated with all calendars. /// @@ -183,7 +169,7 @@ mod private { /// [`DynamicDataMarker`]. For example, this trait can be implemented for [`YearNamesV1Marker`]. /// /// This trait serves as a building block for a cross-calendar [`BoundDataProvider`]. -pub trait CalMarkers: private::Sealed +pub trait CalMarkers: UnstableSealed where M: DynamicDataMarker, { @@ -228,14 +214,14 @@ where #[allow(clippy::exhaustive_enums)] // empty enum pub enum FullDataCalMarkers {} -impl private::Sealed for FullDataCalMarkers {} +impl UnstableSealed for FullDataCalMarkers {} /// Implementation of [`CalMarkers`] that includes data for no calendars. #[derive(Debug)] #[allow(clippy::exhaustive_enums)] // empty enum pub enum NoDataCalMarkers {} -impl private::Sealed for NoDataCalMarkers {} +impl UnstableSealed for NoDataCalMarkers {} impl CalMarkers for NoDataCalMarkers where diff --git a/components/datetime/src/scaffold/mod.rs b/components/datetime/src/scaffold/mod.rs new file mode 100644 index 0000000000..530eab01f1 --- /dev/null +++ b/components/datetime/src/scaffold/mod.rs @@ -0,0 +1,25 @@ +// This file is part of ICU4X. For terms of use, please see the file +// called LICENSE at the top level of the ICU4X source tree +// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). + +//! Scaffolding traits and types for the datetime crate. +//! +//! Items in this module are mostly for trait bounds. Most users should not need to reference +//! these items in userland code. + +mod calendar; + +pub(crate) use calendar::AnyCalendarProvider; +pub use calendar::CalMarkers; +pub use calendar::CldrCalendar; +pub use calendar::FullDataCalMarkers; +pub use calendar::NoDataCalMarkers; + +/// Trait marking other traits that are considered unstable and should not generally be +/// implemented outside of the datetime crate. +/// +///
+/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways, +/// including in SemVer minor releases. Do not implement this trait in userland. +///
+pub trait UnstableSealed {} diff --git a/components/datetime/tests/datetime.rs b/components/datetime/tests/datetime.rs index 42b5df3f3f..705e90ba44 100644 --- a/components/datetime/tests/datetime.rs +++ b/components/datetime/tests/datetime.rs @@ -25,7 +25,7 @@ use icu_calendar::{ AsCalendar, Calendar, DateTime, Gregorian, Iso, }; use icu_datetime::neo_skeleton::NeoDateTimeSkeleton; -use icu_datetime::CldrCalendar; +use icu_datetime::scaffold::CldrCalendar; use icu_datetime::{ neo::{NeoFormatter, TypedNeoFormatter}, neo_pattern::DateTimePattern, diff --git a/tools/make/diplomat-coverage/src/allowlist.rs b/tools/make/diplomat-coverage/src/allowlist.rs index ef3ecbcfdd..94885df1e8 100644 --- a/tools/make/diplomat-coverage/src/allowlist.rs +++ b/tools/make/diplomat-coverage/src/allowlist.rs @@ -208,6 +208,9 @@ lazy_static::lazy_static! { // may in the future be exposed for options "icu::datetime::fields", + // Datetime scaffolding + "icu::datetime::scaffold", + // experimental "icu::datetime::neo", "icu::datetime::neo_marker",