diff --git a/components/datetime/src/any/datetime.rs b/components/datetime/src/any/datetime.rs index 10c46e92342..290b014ee9f 100644 --- a/components/datetime/src/any/datetime.rs +++ b/components/datetime/src/any/datetime.rs @@ -2,8 +2,6 @@ // called LICENSE at the top level of the ICU4X source tree // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). -#[cfg(feature = "experimental")] -use crate::options::components; use crate::provider::{calendar::*, date_time::PatternSelector}; use crate::{calendar, options::DateTimeFormatterOptions, raw, DateFormatter, TimeFormatter}; use crate::{input::DateTimeInput, DateTimeError, FormattedDateTime}; @@ -277,7 +275,7 @@ impl DateTimeFormatter { /// Constructor that supports experimental options with compiled data. /// - /// ✨ *Enabled with the `compiled_data` Cargo feature.* + /// ✨ *Enabled with the `compiled_data` and `experimental` Cargo features.* /// /// [📚 Help choosing a constructor](icu_provider::constructors) /// @@ -499,11 +497,20 @@ where { Ok(self.format(value)?.write_to_string().into_owned()) } - /// Returns a [`components::Bag`] that represents the resolved components for the + /// Returns a [`components::Bag`](crate::options::components::Bag) that represents the resolved components for the /// options that were provided to the [`DateTimeFormatter`]. The developer may request /// a certain set of options for a [`DateTimeFormatter`] but the locale and resolution /// algorithm may change certain details of what actually gets resolved. /// + /// ✨ *Enabled with the `experimental` Cargo feature.* + /// + ///
+ /// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, + /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature + /// of the icu meta-crate. Use with caution. + /// #1317 + ///
+ /// /// # Examples /// /// ``` @@ -529,7 +536,7 @@ where { /// assert_eq!(dtf.resolve_components(), expected_components_bag); /// ``` #[cfg(feature = "experimental")] - pub fn resolve_components(&self) -> components::Bag { + pub fn resolve_components(&self) -> crate::options::components::Bag { self.0.resolve_components() } diff --git a/components/datetime/src/any/zoned_datetime.rs b/components/datetime/src/any/zoned_datetime.rs index b45d45b5a6e..ab4b7911c7e 100644 --- a/components/datetime/src/any/zoned_datetime.rs +++ b/components/datetime/src/any/zoned_datetime.rs @@ -127,10 +127,17 @@ impl ZonedDateTimeFormatter { /// This method will pick the calendar off of the locale; and if unspecified or unknown will fall back to the default /// calendar for the locale. See [`AnyCalendarKind`] for a list of supported calendars. /// - /// ✨ *Enabled with the `compiled_data` Cargo feature.* + /// ✨ *Enabled with the `compiled_data` and `experimental` Cargo features.* /// /// [📚 Help choosing a constructor](icu_provider::constructors) /// + ///
+ /// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, + /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature + /// of the icu meta-crate. Use with caution. + /// #1317 + ///
+ /// /// # Examples /// /// ``` diff --git a/components/datetime/src/datetime.rs b/components/datetime/src/datetime.rs index 3cffa9dcc01..51d54dd495c 100644 --- a/components/datetime/src/datetime.rs +++ b/components/datetime/src/datetime.rs @@ -24,9 +24,6 @@ use crate::{ DateTimeError, FormattedDateTime, }; -#[cfg(feature = "experimental")] -use crate::options::components; - /// [`TimeFormatter`] is a structure of the [`icu_datetime`] component that provides time formatting only. /// When constructed, it uses data from the [data provider], selected locale and provided preferences to /// collect all data necessary to format any time into that locale. @@ -591,7 +588,7 @@ where { /// Constructor that supports experimental options using compiled data. /// - /// ✨ *Enabled with the `compiled_data` Cargo feature.* + /// ✨ *Enabled with the `compiled_data` and `experimental` Cargo features.* /// /// [📚 Help choosing a constructor](icu_provider::constructors) /// @@ -661,41 +658,7 @@ where { )) } - /// Constructor that supports experimental options. - /// - ///
- /// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, - /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature - /// of the icu meta-crate. Use with caution. - /// #1317 - ///
- /// - /// # Examples - /// - /// ``` - /// use icu::calendar::{DateTime, Gregorian}; - /// use icu::datetime::{options::components, TypedDateTimeFormatter}; - /// use icu::locid::locale; - /// use icu_provider::AsDeserializingBufferProvider; - /// use writeable::assert_writeable_eq; - /// - /// let mut options = components::Bag::default(); - /// options.year = Some(components::Year::Numeric); - /// options.month = Some(components::Month::Long); - /// - /// let dtf = TypedDateTimeFormatter::::try_new_experimental( - /// &locale!("en").into(), - /// options.into(), - /// ) - /// .unwrap(); - /// - /// let datetime = - /// DateTime::try_new_gregorian_datetime(2022, 8, 31, 1, 2, 3).unwrap(); - /// - /// assert_writeable_eq!(dtf.format(&datetime), "August 2022"); - /// ``` - /// - /// [data provider]: icu_provider + #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new_experimental)] #[cfg(feature = "experimental")] #[inline] pub fn try_new_experimental_unstable( @@ -781,7 +744,7 @@ where { self.format(value).write_to_string().into_owned() } - /// Returns a [`components::Bag`] that represents the resolved components for the + /// Returns a [`components::Bag`](crate::options::components::Bag) that represents the resolved components for the /// options that were provided to the [`TypedDateTimeFormatter`]. The developer may request /// a certain set of options for a [`TypedDateTimeFormatter`] but the locale and resolution /// algorithm may change certain details of what actually gets resolved. @@ -811,7 +774,7 @@ where { /// assert_eq!(dtf.resolve_components(), expected_components_bag); /// ``` #[cfg(feature = "experimental")] - pub fn resolve_components(&self) -> components::Bag { + pub fn resolve_components(&self) -> crate::options::components::Bag { self.0.resolve_components() } } diff --git a/components/datetime/src/error.rs b/components/datetime/src/error.rs index f9645f438b1..47ba9bbdefc 100644 --- a/components/datetime/src/error.rs +++ b/components/datetime/src/error.rs @@ -5,8 +5,6 @@ use crate::fields::FieldSymbol; use crate::input::CalendarError; use crate::pattern::PatternError; -#[cfg(feature = "experimental")] -use crate::skeleton::SkeletonError; use displaydoc::Display; use icu_calendar::any_calendar::AnyCalendarKind; use icu_calendar::types::MonthCode; @@ -39,7 +37,7 @@ pub enum DateTimeError { /// An error originating from skeleton matching. #[displaydoc("{0}")] #[cfg(feature = "experimental")] - Skeleton(SkeletonError), + Skeleton(crate::skeleton::SkeletonError), /// An error originating from an unsupported field in a datetime format. #[displaydoc("Unsupported field: {0:?}")] UnsupportedField(FieldSymbol), @@ -96,13 +94,6 @@ impl From for DateTimeError { } } -#[cfg(feature = "experimental")] -impl From for DateTimeError { - fn from(e: SkeletonError) -> Self { - DateTimeError::Skeleton(e) - } -} - impl From for DateTimeError { fn from(e: PluralsError) -> Self { DateTimeError::PluralRules(e) diff --git a/components/datetime/src/options/components.rs b/components/datetime/src/options/components.rs index 5666767e7c8..1d56474796a 100644 --- a/components/datetime/src/options/components.rs +++ b/components/datetime/src/options/components.rs @@ -4,6 +4,8 @@ //! 🚧 \[Experimental\] Options for constructing DateTimeFormatter objects by each component style. //! +//! ✨ *Enabled with the `experimental` Cargo feature.* +//! //!
//! 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, //! including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature @@ -85,9 +87,6 @@ use crate::{ pattern::{runtime::PatternPlurals, PatternItem}, }; -#[cfg(feature = "experimental")] -use alloc::vec::Vec; - use super::preferences; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -146,8 +145,8 @@ impl Bag { /// significant field to least significant. This is the order the fields are listed in /// the UTS 35 table - https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table #[cfg(any(test, feature = "experimental"))] // only used in test and experimental code - pub(crate) fn to_vec_fields(&self) -> Vec { - let mut fields = Vec::new(); + pub(crate) fn to_vec_fields(&self) -> alloc::vec::Vec { + let mut fields = alloc::vec::Vec::new(); if let Some(era) = self.era { fields.push(Field { symbol: FieldSymbol::Era, diff --git a/components/datetime/src/options/mod.rs b/components/datetime/src/options/mod.rs index 86c3dec63e4..72412620007 100644 --- a/components/datetime/src/options/mod.rs +++ b/components/datetime/src/options/mod.rs @@ -62,6 +62,8 @@ pub enum DateTimeFormatterOptions { Length(length::Bag), /// Bag of components describing which fields and how should be displayed. /// + /// ✨ *Enabled with the `experimental` Cargo feature.* + /// ///
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature diff --git a/components/datetime/src/options/preferences.rs b/components/datetime/src/options/preferences.rs index 330319ad728..34913db6027 100644 --- a/components/datetime/src/options/preferences.rs +++ b/components/datetime/src/options/preferences.rs @@ -4,6 +4,8 @@ //! 🚧 \[Experimental\] Types to hold user preferences to configure a DateTimeFormatter. //! +//! ✨ *Enabled with the `experimental` Cargo feature.* +//! //! Preferences is a bag of options to be associated with either [`length::Bag`] or [`components::Bag`] //! which provides information on user preferences that can affect the result of the formatting. //! diff --git a/components/datetime/src/provider/date_time.rs b/components/datetime/src/provider/date_time.rs index e50826b5f60..e6f45ccf2d6 100644 --- a/components/datetime/src/provider/date_time.rs +++ b/components/datetime/src/provider/date_time.rs @@ -277,7 +277,6 @@ where ))) } - #[cfg(feature = "experimental")] fn skeleton_data_payload(&self) -> Result> { use icu_locid::extensions::unicode::{key, value}; use tinystr::tinystr; diff --git a/components/datetime/src/raw/datetime.rs b/components/datetime/src/raw/datetime.rs index c8137fd68f9..4baf875cc5e 100644 --- a/components/datetime/src/raw/datetime.rs +++ b/components/datetime/src/raw/datetime.rs @@ -5,8 +5,6 @@ //! The collection of code that is needed for handling formatting operations for DateTimes. //! Central to this is the [`DateTimeFormatter`]. -#[cfg(feature = "experimental")] -use crate::options::components; use crate::{ format::datetime, input::{DateInput, DateTimeInput, ExtractedDateTimeInput, IsoTimeInput}, @@ -526,10 +524,10 @@ impl DateTimeFormatter { } } - /// Returns a [`components::Bag`] that represents the resolved components for the + /// Returns a [`components::Bag`](crate::options::components::Bag) that represents the resolved components for the /// options that were provided to the [`DateTimeFormatter`]. #[cfg(feature = "experimental")] - pub fn resolve_components(&self) -> components::Bag { - components::Bag::from(&self.patterns.get().0) + pub fn resolve_components(&self) -> crate::options::components::Bag { + crate::options::components::Bag::from(&self.patterns.get().0) } } diff --git a/components/datetime/src/skeleton/error.rs b/components/datetime/src/skeleton/error.rs index 5584a1dc6e3..e85cb24bec8 100644 --- a/components/datetime/src/skeleton/error.rs +++ b/components/datetime/src/skeleton/error.rs @@ -34,6 +34,13 @@ pub enum SkeletonError { #[cfg(feature = "std")] impl std::error::Error for SkeletonError {} +#[cfg(feature = "experimental")] +impl From for crate::DateTimeError { + fn from(e: SkeletonError) -> Self { + crate::DateTimeError::Skeleton(e) + } +} + impl From for SkeletonError { fn from(e: fields::Error) -> Self { SkeletonError::Fields(e) diff --git a/components/datetime/src/zoned_datetime.rs b/components/datetime/src/zoned_datetime.rs index 4cda8686af1..2282fc2eeb9 100644 --- a/components/datetime/src/zoned_datetime.rs +++ b/components/datetime/src/zoned_datetime.rs @@ -85,32 +85,22 @@ impl TypedZonedDateTimeFormatter { /// /// [📚 Help choosing a constructor](icu_provider::constructors) /// - ///
- /// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, - /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature - /// of the icu meta-crate. Use with caution. - /// #1317 - ///
- /// /// # Examples /// /// ``` /// use icu::calendar::{DateTime, Gregorian}; /// use icu::datetime::time_zone::TimeZoneFormatterOptions; - /// use icu::datetime::{options::components, TypedZonedDateTimeFormatter}; + /// use icu::datetime::{options::length, TypedZonedDateTimeFormatter}; /// use icu::locid::locale; /// use icu::timezone::CustomTimeZone; - /// use icu_provider::AsDeserializingBufferProvider; /// use writeable::assert_writeable_eq; /// - /// let mut options = components::Bag::default(); - /// options.year = Some(components::Year::Numeric); - /// options.month = Some(components::Month::Long); - /// options.hour = Some(components::Numeric::Numeric); - /// options.minute = Some(components::Numeric::Numeric); - /// options.time_zone_name = Some(components::TimeZoneName::GmtOffset); + /// let options = length::Bag::from_date_time_style( + /// length::Date::Medium, + /// length::Time::Long, + /// ); /// - /// let zdtf = TypedZonedDateTimeFormatter::::try_new_experimental( + /// let zdtf = TypedZonedDateTimeFormatter::::try_new( /// &locale!("en").into(), /// options.into(), /// TimeZoneFormatterOptions::default(), @@ -122,15 +112,14 @@ impl TypedZonedDateTimeFormatter { /// /// assert_writeable_eq!( /// zdtf.format(&datetime, &CustomTimeZone::utc()), - /// "August 2022, 01:02 GMT", + /// "Aug 31, 2022, 1:02:03 AM GMT", /// ); /// ``` /// /// [data provider]: icu_provider - #[cfg(feature = "experimental")] - #[cfg(feature = "compiled_data")] #[inline] - pub fn try_new_experimental( + #[cfg(feature = "compiled_data")] + pub fn try_new( locale: &DataLocale, date_time_format_options: DateTimeFormatterOptions, time_zone_format_options: TimeZoneFormatterOptions, @@ -139,11 +128,10 @@ impl TypedZonedDateTimeFormatter { crate::provider::Baked: DataProvider + DataProvider, { - let patterns = PatternSelector::for_options_experimental( + let patterns = PatternSelector::for_options( &crate::provider::Baked, calendar::load_lengths_for_cldr_calendar::(&crate::provider::Baked, locale)?, locale, - &C::DEFAULT_BCP_47_IDENTIFIER, &date_time_format_options, )?; Ok(Self( @@ -162,10 +150,17 @@ impl TypedZonedDateTimeFormatter { )) } - #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new_experimental)] - #[cfg(feature = "experimental")] + icu_provider::gen_any_buffer_data_constructors!( + locale: include, + date_time_format_options: DateTimeFormatterOptions, + time_zone_format_options: TimeZoneFormatterOptions, + error: DateTimeError, + #[cfg(skip)] + ); + + #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)] #[inline] - pub fn try_new_experimental_unstable

( + pub fn try_new_unstable

( provider: &P, locale: &DataLocale, date_time_format_options: DateTimeFormatterOptions, @@ -176,7 +171,6 @@ impl TypedZonedDateTimeFormatter { + DataProvider<::DateLengthsV1Marker> + DataProvider + DataProvider - + DataProvider + DataProvider + DataProvider + DataProvider @@ -188,11 +182,10 @@ impl TypedZonedDateTimeFormatter { + DataProvider + ?Sized, { - let patterns = PatternSelector::for_options_experimental( + let patterns = PatternSelector::for_options( provider, calendar::load_lengths_for_cldr_calendar::(provider, locale)?, locale, - &C::DEFAULT_BCP_47_IDENTIFIER, &date_time_format_options, )?; Ok(Self( @@ -210,26 +203,36 @@ impl TypedZonedDateTimeFormatter { /// Constructor that takes a selected locale and a list of [`DateTimeFormatterOptions`]. /// It collects all data necessary to format zoned datetime values into the given locale. /// - /// ✨ *Enabled with the `compiled_data` Cargo feature.* + /// ✨ *Enabled with the `compiled_data` and `experimental` Cargo features.* /// /// [📚 Help choosing a constructor](icu_provider::constructors) /// + ///

+ /// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways, + /// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature + /// of the icu meta-crate. Use with caution. + /// #1317 + ///
+ /// /// # Examples /// /// ``` /// use icu::calendar::{DateTime, Gregorian}; /// use icu::datetime::time_zone::TimeZoneFormatterOptions; - /// use icu::datetime::{options::length, TypedZonedDateTimeFormatter}; + /// use icu::datetime::{options::components, TypedZonedDateTimeFormatter}; /// use icu::locid::locale; /// use icu::timezone::CustomTimeZone; + /// use icu_provider::AsDeserializingBufferProvider; /// use writeable::assert_writeable_eq; /// - /// let options = length::Bag::from_date_time_style( - /// length::Date::Medium, - /// length::Time::Long, - /// ); + /// let mut options = components::Bag::default(); + /// options.year = Some(components::Year::Numeric); + /// options.month = Some(components::Month::Long); + /// options.hour = Some(components::Numeric::Numeric); + /// options.minute = Some(components::Numeric::Numeric); + /// options.time_zone_name = Some(components::TimeZoneName::GmtOffset); /// - /// let zdtf = TypedZonedDateTimeFormatter::::try_new( + /// let zdtf = TypedZonedDateTimeFormatter::::try_new_experimental( /// &locale!("en").into(), /// options.into(), /// TimeZoneFormatterOptions::default(), @@ -241,14 +244,15 @@ impl TypedZonedDateTimeFormatter { /// /// assert_writeable_eq!( /// zdtf.format(&datetime, &CustomTimeZone::utc()), - /// "Aug 31, 2022, 1:02:03 AM GMT", + /// "August 2022, 01:02 GMT", /// ); /// ``` /// /// [data provider]: icu_provider - #[inline] + #[cfg(feature = "experimental")] #[cfg(feature = "compiled_data")] - pub fn try_new( + #[inline] + pub fn try_new_experimental( locale: &DataLocale, date_time_format_options: DateTimeFormatterOptions, time_zone_format_options: TimeZoneFormatterOptions, @@ -257,10 +261,11 @@ impl TypedZonedDateTimeFormatter { crate::provider::Baked: DataProvider + DataProvider, { - let patterns = PatternSelector::for_options( + let patterns = PatternSelector::for_options_experimental( &crate::provider::Baked, calendar::load_lengths_for_cldr_calendar::(&crate::provider::Baked, locale)?, locale, + &C::DEFAULT_BCP_47_IDENTIFIER, &date_time_format_options, )?; Ok(Self( @@ -279,17 +284,10 @@ impl TypedZonedDateTimeFormatter { )) } - icu_provider::gen_any_buffer_data_constructors!( - locale: include, - date_time_format_options: DateTimeFormatterOptions, - time_zone_format_options: TimeZoneFormatterOptions, - error: DateTimeError, - #[cfg(skip)] - ); - - #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)] + #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new_experimental)] + #[cfg(feature = "experimental")] #[inline] - pub fn try_new_unstable

( + pub fn try_new_experimental_unstable

( provider: &P, locale: &DataLocale, date_time_format_options: DateTimeFormatterOptions, @@ -300,6 +298,7 @@ impl TypedZonedDateTimeFormatter { + DataProvider<::DateLengthsV1Marker> + DataProvider + DataProvider + + DataProvider + DataProvider + DataProvider + DataProvider @@ -311,10 +310,11 @@ impl TypedZonedDateTimeFormatter { + DataProvider + ?Sized, { - let patterns = PatternSelector::for_options( + let patterns = PatternSelector::for_options_experimental( provider, calendar::load_lengths_for_cldr_calendar::(provider, locale)?, locale, + &C::DEFAULT_BCP_47_IDENTIFIER, &date_time_format_options, )?; Ok(Self(