Skip to content

Commit a766bbd

Browse files
committed
Clean up icu_datetime/experimental (#4096)
1 parent b68c42e commit a766bbd

File tree

11 files changed

+93
-118
lines changed

11 files changed

+93
-118
lines changed

components/datetime/src/any/datetime.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// called LICENSE at the top level of the ICU4X source tree
33
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
44

5-
#[cfg(feature = "experimental")]
6-
use crate::options::components;
75
use crate::provider::{calendar::*, date_time::PatternSelector};
86
use crate::{calendar, options::DateTimeFormatterOptions, raw, DateFormatter, TimeFormatter};
97
use crate::{input::DateTimeInput, DateTimeError, FormattedDateTime};
@@ -277,7 +275,7 @@ impl DateTimeFormatter {
277275

278276
/// Constructor that supports experimental options with compiled data.
279277
///
280-
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
278+
/// ✨ *Enabled with the `compiled_data` and `experimental` Cargo features.*
281279
///
282280
/// [📚 Help choosing a constructor](icu_provider::constructors)
283281
///
@@ -499,11 +497,20 @@ where {
499497
Ok(self.format(value)?.write_to_string().into_owned())
500498
}
501499

502-
/// Returns a [`components::Bag`] that represents the resolved components for the
500+
/// Returns a [`components::Bag`](crate::options::components::Bag) that represents the resolved components for the
503501
/// options that were provided to the [`DateTimeFormatter`]. The developer may request
504502
/// a certain set of options for a [`DateTimeFormatter`] but the locale and resolution
505503
/// algorithm may change certain details of what actually gets resolved.
506504
///
505+
/// ✨ *Enabled with the `experimental` Cargo feature.*
506+
///
507+
/// <div class="stab unstable">
508+
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
509+
/// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature
510+
/// of the icu meta-crate. Use with caution.
511+
/// <a href="https://github.com/unicode-org/icu4x/issues/1317">#1317</a>
512+
/// </div>
513+
///
507514
/// # Examples
508515
///
509516
/// ```
@@ -529,7 +536,7 @@ where {
529536
/// assert_eq!(dtf.resolve_components(), expected_components_bag);
530537
/// ```
531538
#[cfg(feature = "experimental")]
532-
pub fn resolve_components(&self) -> components::Bag {
539+
pub fn resolve_components(&self) -> crate::options::components::Bag {
533540
self.0.resolve_components()
534541
}
535542

components/datetime/src/any/zoned_datetime.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,17 @@ impl ZonedDateTimeFormatter {
127127
/// This method will pick the calendar off of the locale; and if unspecified or unknown will fall back to the default
128128
/// calendar for the locale. See [`AnyCalendarKind`] for a list of supported calendars.
129129
///
130-
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
130+
/// ✨ *Enabled with the `compiled_data` and `experimental` Cargo features.*
131131
///
132132
/// [📚 Help choosing a constructor](icu_provider::constructors)
133133
///
134+
/// <div class="stab unstable">
135+
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
136+
/// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature
137+
/// of the icu meta-crate. Use with caution.
138+
/// <a href="https://github.com/unicode-org/icu4x/issues/1317">#1317</a>
139+
/// </div>
140+
///
134141
/// # Examples
135142
///
136143
/// ```

components/datetime/src/datetime.rs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ use crate::{
2424
DateTimeError, FormattedDateTime,
2525
};
2626

27-
#[cfg(feature = "experimental")]
28-
use crate::options::components;
29-
3027
/// [`TimeFormatter`] is a structure of the [`icu_datetime`] component that provides time formatting only.
3128
/// When constructed, it uses data from the [data provider], selected locale and provided preferences to
3229
/// collect all data necessary to format any time into that locale.
@@ -591,7 +588,7 @@ where {
591588

592589
/// Constructor that supports experimental options using compiled data.
593590
///
594-
/// ✨ *Enabled with the `compiled_data` Cargo feature.*
591+
/// ✨ *Enabled with the `compiled_data` and `experimental` Cargo features.*
595592
///
596593
/// [📚 Help choosing a constructor](icu_provider::constructors)
597594
///
@@ -661,41 +658,7 @@ where {
661658
))
662659
}
663660

664-
/// Constructor that supports experimental options.
665-
///
666-
/// <div class="stab unstable">
667-
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
668-
/// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature
669-
/// of the icu meta-crate. Use with caution.
670-
/// <a href="https://github.com/unicode-org/icu4x/issues/1317">#1317</a>
671-
/// </div>
672-
///
673-
/// # Examples
674-
///
675-
/// ```
676-
/// use icu::calendar::{DateTime, Gregorian};
677-
/// use icu::datetime::{options::components, TypedDateTimeFormatter};
678-
/// use icu::locid::locale;
679-
/// use icu_provider::AsDeserializingBufferProvider;
680-
/// use writeable::assert_writeable_eq;
681-
///
682-
/// let mut options = components::Bag::default();
683-
/// options.year = Some(components::Year::Numeric);
684-
/// options.month = Some(components::Month::Long);
685-
///
686-
/// let dtf = TypedDateTimeFormatter::<Gregorian>::try_new_experimental(
687-
/// &locale!("en").into(),
688-
/// options.into(),
689-
/// )
690-
/// .unwrap();
691-
///
692-
/// let datetime =
693-
/// DateTime::try_new_gregorian_datetime(2022, 8, 31, 1, 2, 3).unwrap();
694-
///
695-
/// assert_writeable_eq!(dtf.format(&datetime), "August 2022");
696-
/// ```
697-
///
698-
/// [data provider]: icu_provider
661+
#[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new_experimental)]
699662
#[cfg(feature = "experimental")]
700663
#[inline]
701664
pub fn try_new_experimental_unstable<D>(
@@ -781,7 +744,7 @@ where {
781744
self.format(value).write_to_string().into_owned()
782745
}
783746

784-
/// Returns a [`components::Bag`] that represents the resolved components for the
747+
/// Returns a [`components::Bag`](crate::options::components::Bag) that represents the resolved components for the
785748
/// options that were provided to the [`TypedDateTimeFormatter`]. The developer may request
786749
/// a certain set of options for a [`TypedDateTimeFormatter`] but the locale and resolution
787750
/// algorithm may change certain details of what actually gets resolved.
@@ -811,7 +774,7 @@ where {
811774
/// assert_eq!(dtf.resolve_components(), expected_components_bag);
812775
/// ```
813776
#[cfg(feature = "experimental")]
814-
pub fn resolve_components(&self) -> components::Bag {
777+
pub fn resolve_components(&self) -> crate::options::components::Bag {
815778
self.0.resolve_components()
816779
}
817780
}

components/datetime/src/error.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
use crate::fields::FieldSymbol;
66
use crate::input::CalendarError;
77
use crate::pattern::PatternError;
8-
#[cfg(feature = "experimental")]
9-
use crate::skeleton::SkeletonError;
108
use displaydoc::Display;
119
use icu_calendar::any_calendar::AnyCalendarKind;
1210
use icu_calendar::types::MonthCode;
@@ -39,7 +37,7 @@ pub enum DateTimeError {
3937
/// An error originating from skeleton matching.
4038
#[displaydoc("{0}")]
4139
#[cfg(feature = "experimental")]
42-
Skeleton(SkeletonError),
40+
Skeleton(crate::skeleton::SkeletonError),
4341
/// An error originating from an unsupported field in a datetime format.
4442
#[displaydoc("Unsupported field: {0:?}")]
4543
UnsupportedField(FieldSymbol),
@@ -96,13 +94,6 @@ impl From<core::fmt::Error> for DateTimeError {
9694
}
9795
}
9896

99-
#[cfg(feature = "experimental")]
100-
impl From<SkeletonError> for DateTimeError {
101-
fn from(e: SkeletonError) -> Self {
102-
DateTimeError::Skeleton(e)
103-
}
104-
}
105-
10697
impl From<PluralsError> for DateTimeError {
10798
fn from(e: PluralsError) -> Self {
10899
DateTimeError::PluralRules(e)

components/datetime/src/options/components.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
//! 🚧 \[Experimental\] Options for constructing DateTimeFormatter objects by each component style.
66
//!
7+
//! ✨ *Enabled with the `experimental` Cargo feature.*
8+
//!
79
//! <div class="stab unstable">
810
//! 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
911
//! including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature
@@ -85,9 +87,6 @@ use crate::{
8587
pattern::{runtime::PatternPlurals, PatternItem},
8688
};
8789

88-
#[cfg(feature = "experimental")]
89-
use alloc::vec::Vec;
90-
9190
use super::preferences;
9291
#[cfg(feature = "serde")]
9392
use serde::{Deserialize, Serialize};
@@ -146,8 +145,8 @@ impl Bag {
146145
/// significant field to least significant. This is the order the fields are listed in
147146
/// the UTS 35 table - https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
148147
#[cfg(any(test, feature = "experimental"))] // only used in test and experimental code
149-
pub(crate) fn to_vec_fields(&self) -> Vec<Field> {
150-
let mut fields = Vec::new();
148+
pub(crate) fn to_vec_fields(&self) -> alloc::vec::Vec<Field> {
149+
let mut fields = alloc::vec::Vec::new();
151150
if let Some(era) = self.era {
152151
fields.push(Field {
153152
symbol: FieldSymbol::Era,

components/datetime/src/options/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub enum DateTimeFormatterOptions {
6262
Length(length::Bag),
6363
/// Bag of components describing which fields and how should be displayed.
6464
///
65+
/// ✨ *Enabled with the `experimental` Cargo feature.*
66+
///
6567
/// <div class="stab unstable">
6668
/// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
6769
/// including in SemVer minor releases. It can be enabled with the "experimental" Cargo feature

components/datetime/src/options/preferences.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
//! 🚧 \[Experimental\] Types to hold user preferences to configure a DateTimeFormatter.
66
//!
7+
//! ✨ *Enabled with the `experimental` Cargo feature.*
8+
//!
79
//! Preferences is a bag of options to be associated with either [`length::Bag`] or [`components::Bag`]
810
//! which provides information on user preferences that can affect the result of the formatting.
911
//!

components/datetime/src/provider/date_time.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ where
277277
)))
278278
}
279279

280-
#[cfg(feature = "experimental")]
281280
fn skeleton_data_payload(&self) -> Result<DataPayload<DateSkeletonPatternsV1Marker>> {
282281
use icu_locid::extensions::unicode::{key, value};
283282
use tinystr::tinystr;

components/datetime/src/raw/datetime.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
//! The collection of code that is needed for handling formatting operations for DateTimes.
66
//! Central to this is the [`DateTimeFormatter`].
77
8-
#[cfg(feature = "experimental")]
9-
use crate::options::components;
108
use crate::{
119
format::datetime,
1210
input::{DateInput, DateTimeInput, ExtractedDateTimeInput, IsoTimeInput},
@@ -526,10 +524,10 @@ impl DateTimeFormatter {
526524
}
527525
}
528526

529-
/// Returns a [`components::Bag`] that represents the resolved components for the
527+
/// Returns a [`components::Bag`](crate::options::components::Bag) that represents the resolved components for the
530528
/// options that were provided to the [`DateTimeFormatter`].
531529
#[cfg(feature = "experimental")]
532-
pub fn resolve_components(&self) -> components::Bag {
533-
components::Bag::from(&self.patterns.get().0)
530+
pub fn resolve_components(&self) -> crate::options::components::Bag {
531+
crate::options::components::Bag::from(&self.patterns.get().0)
534532
}
535533
}

components/datetime/src/skeleton/error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ pub enum SkeletonError {
3434
#[cfg(feature = "std")]
3535
impl std::error::Error for SkeletonError {}
3636

37+
#[cfg(feature = "experimental")]
38+
impl From<SkeletonError> for crate::DateTimeError {
39+
fn from(e: SkeletonError) -> Self {
40+
crate::DateTimeError::Skeleton(e)
41+
}
42+
}
43+
3744
impl From<fields::Error> for SkeletonError {
3845
fn from(e: fields::Error) -> Self {
3946
SkeletonError::Fields(e)

0 commit comments

Comments
 (0)