Skip to content

Commit 3bdc89c

Browse files
committed
unstable
1 parent 12a185d commit 3bdc89c

File tree

21 files changed

+208
-62
lines changed

21 files changed

+208
-62
lines changed

components/calendar/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ datagen = ["serde", "dep:databake", "zerovec/databake", "tinystr/databake", "all
5656
compiled_data = ["dep:icu_calendar_data", "dep:icu_locale", "icu_locale?/compiled_data", "icu_provider/baked"]
5757

5858
alloc = []
59+
unstable = []
5960

6061
[[bench]]
6162
name = "date"

components/calendar/src/any_calendar.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,12 @@ impl AnyCalendar {
650650
}
651651

652652
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
653+
///
654+
/// <div class="stab unstable">
655+
/// 🚧 This method is considered unstable; it may change at any time, in breaking or non-breaking ways,
656+
/// including in SemVer minor releases. This requires the `unstable` Cargo feature.
657+
/// </div>
658+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
653659
pub fn try_new_unstable<P>(provider: &P, kind: AnyCalendarKind) -> Result<Self, DataError>
654660
where
655661
P: DataProvider<crate::provider::CalendarJapaneseModernV1>
@@ -905,29 +911,43 @@ impl fmt::Display for AnyCalendarKind {
905911
}
906912

907913
/// Trait for calendars that may be converted to [`AnyCalendar`]
914+
///
915+
/// <div class="stab unstable">
916+
/// 🚫 This trait is sealed; it should not be implemented by user code. If an API requests an item that implements this
917+
/// trait, please consider using a type from the implementors listed below.
918+
///
919+
/// It is still possible to implement this trait in userland (since `UnstableSealed` is public),
920+
/// do not do so unless you are prepared for things to occasionally break.
921+
/// </div>
908922
pub trait IntoAnyCalendar: Calendar + Sized {
909923
/// Convert this calendar into an [`AnyCalendar`], moving it
910924
///
911925
/// You should not need to call this method directly
926+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
912927
fn to_any(self) -> AnyCalendar;
913928

914929
/// The [`AnyCalendarKind`] enum variant associated with this calendar
930+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
915931
fn kind(&self) -> AnyCalendarKind;
916932

917933
/// Move an [`AnyCalendar`] into a `Self`, or returning it as an error
934+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
918935
/// if the types do not match.
919936
///
920937
/// You should not need to call this method directly
938+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
921939
fn from_any(any: AnyCalendar) -> Result<Self, AnyCalendar>;
922940

923941
/// Convert an [`AnyCalendar`] reference into a `Self` reference.
924942
///
925943
/// You should not need to call this method directly
944+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
926945
fn from_any_ref(any: &AnyCalendar) -> Option<&Self>;
927946

928947
/// Convert a date for this calendar into an `AnyDateInner`
929948
///
930949
/// You should not need to call this method directly
950+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
931951
fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner;
932952
}
933953

components/calendar/src/cal/chinese.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ impl Chinese {
135135
]);
136136

137137
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
138+
///
139+
/// <div class="stab unstable">
140+
/// 🚧 This method is considered unstable; it may change at any time, in breaking or non-breaking ways,
141+
/// including in SemVer minor releases. This requires the `unstable` Cargo feature.
142+
/// </div>
143+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
138144
pub fn try_new_unstable<D: DataProvider<CalendarChineseV1> + ?Sized>(
139145
provider: &D,
140146
) -> Result<Self, DataError> {
@@ -218,17 +224,11 @@ impl Calendar for Chinese {
218224
date.0.days_in_month()
219225
}
220226

221-
#[doc(hidden)] // unstable
222227
fn offset_date(&self, date: &mut Self::DateInner, offset: DateDuration<Self>) {
223228
date.0.offset_date(offset, &self.get_precomputed_data());
224229
}
225230

226-
#[doc(hidden)] // unstable
227231
#[allow(clippy::field_reassign_with_default)]
228-
/// Calculate `date2 - date` as a duration
229-
///
230-
/// `calendar2` is the calendar object associated with `date2`. In case the specific calendar objects
231-
/// differ on date, the date for the first calendar is used, and `date2` may be converted if necessary.
232232
fn until(
233233
&self,
234234
date1: &Self::DateInner,
@@ -322,10 +322,10 @@ impl<A: AsCalendar<Calendar = Chinese>> Date<A> {
322322
.get_precomputed_data()
323323
.load_or_compute_info(related_iso_year);
324324
year.validate_md(month, day)?;
325-
Ok(Date::from_raw(
326-
ChineseDateInner(ArithmeticDate::new_unchecked(year, month, day)),
325+
Ok(Date {
326+
inner: ChineseDateInner(ArithmeticDate::new_unchecked(year, month, day)),
327327
calendar,
328-
))
328+
})
329329
}
330330
}
331331

components/calendar/src/cal/coptic.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,10 @@ impl Date<Coptic> {
216216
pub fn try_new_coptic(year: i32, month: u8, day: u8) -> Result<Date<Coptic>, RangeError> {
217217
ArithmeticDate::new_from_ordinals(year, month, day)
218218
.map(CopticDateInner)
219-
.map(|inner| Date::from_raw(inner, Coptic))
219+
.map(|inner| Date {
220+
inner,
221+
calendar: Coptic,
222+
})
220223
}
221224
}
222225

components/calendar/src/cal/dangi.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ impl Dangi {
133133
]);
134134

135135
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
136+
///
137+
/// <div class="stab unstable">
138+
/// 🚧 This method is considered unstable; it may change at any time, in breaking or non-breaking ways,
139+
/// including in SemVer minor releases. This requires the `unstable` Cargo feature.
140+
/// </div>
141+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
136142
pub fn try_new_unstable<D: DataProvider<CalendarDangiV1> + ?Sized>(
137143
provider: &D,
138144
) -> Result<Self, DataError> {
@@ -303,10 +309,10 @@ impl<A: AsCalendar<Calendar = Dangi>> Date<A> {
303309
.get_precomputed_data()
304310
.load_or_compute_info(related_iso_year);
305311
year.validate_md(month, day)?;
306-
Ok(Date::from_raw(
307-
DangiDateInner(ArithmeticDate::new_unchecked(year, month, day)),
312+
Ok(Date {
313+
inner: DangiDateInner(ArithmeticDate::new_unchecked(year, month, day)),
308314
calendar,
309-
))
315+
})
310316
}
311317
}
312318

components/calendar/src/cal/ethiopian.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,10 @@ impl Date<Ethiopian> {
295295
}
296296
ArithmeticDate::new_from_ordinals(year, month, day)
297297
.map(EthiopianDateInner)
298-
.map(|inner| Date::from_raw(inner, Ethiopian::new_with_era_style(era_style)))
298+
.map(|inner| Date {
299+
inner,
300+
calendar: Ethiopian::new_with_era_style(era_style),
301+
})
299302
}
300303
}
301304

components/calendar/src/cal/hebrew.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,10 @@ impl Date<Hebrew> {
360360

361361
ArithmeticDate::new_from_ordinals(year, month, day)
362362
.map(HebrewDateInner)
363-
.map(|inner| Date::from_raw(inner, Hebrew))
363+
.map(|inner| Date {
364+
inner,
365+
calendar: Hebrew,
366+
})
364367
}
365368
}
366369

components/calendar/src/cal/hijri.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ impl HijriSimulated {
144144
]);
145145

146146
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new_mecca)]
147+
///
148+
/// <div class="stab unstable">
149+
/// 🚧 This method is considered unstable; it may change at any time, in breaking or non-breaking ways,
150+
/// including in SemVer minor releases. This requires the `unstable` Cargo feature.
151+
/// </div>
152+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
147153
pub fn try_new_mecca_unstable<D: DataProvider<CalendarHijriSimulatedMeccaV1> + ?Sized>(
148154
provider: &D,
149155
) -> Result<Self, DataError> {
@@ -620,7 +626,7 @@ impl<A: AsCalendar<Calendar = HijriSimulated>> Date<A> {
620626
let y = calendar.as_calendar().load_or_compute_info(year);
621627
ArithmeticDate::new_from_ordinals(y, month, day)
622628
.map(HijriSimulatedDateInner)
623-
.map(|inner| Date::from_raw(inner, calendar))
629+
.map(|inner| Date { inner, calendar })
624630
}
625631
}
626632

@@ -829,10 +835,10 @@ impl Date<HijriUmmAlQura> {
829835
day: u8,
830836
) -> Result<Date<HijriUmmAlQura>, RangeError> {
831837
let y = HijriUmmAlQura.load_or_compute_info(year);
832-
Ok(Date::from_raw(
833-
HijriUmmAlQuraDateInner(ArithmeticDate::new_from_ordinals(y, month, day)?),
834-
HijriUmmAlQura,
835-
))
838+
Ok(Date {
839+
inner: HijriUmmAlQuraDateInner(ArithmeticDate::new_from_ordinals(y, month, day)?),
840+
calendar: HijriUmmAlQura,
841+
})
836842
}
837843
}
838844

@@ -1041,7 +1047,7 @@ impl<A: AsCalendar<Calendar = HijriTabular>> Date<A> {
10411047
) -> Result<Date<A>, RangeError> {
10421048
ArithmeticDate::new_from_ordinals(year, month, day)
10431049
.map(HijriTabularDateInner)
1044-
.map(|inner| Date::from_raw(inner, calendar))
1050+
.map(|inner| Date { inner, calendar })
10451051
}
10461052
}
10471053

components/calendar/src/cal/indian.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ impl Date<Indian> {
244244
pub fn try_new_indian(year: i32, month: u8, day: u8) -> Result<Date<Indian>, RangeError> {
245245
ArithmeticDate::new_from_ordinals(year, month, day)
246246
.map(IndianDateInner)
247-
.map(|inner| Date::from_raw(inner, Indian))
247+
.map(|inner| Date {
248+
inner,
249+
calendar: Indian,
250+
})
248251
}
249252
}
250253

components/calendar/src/cal/iso.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,10 @@ impl Date<Iso> {
200200
pub fn try_new_iso(year: i32, month: u8, day: u8) -> Result<Date<Iso>, RangeError> {
201201
ArithmeticDate::new_from_ordinals(year, month, day)
202202
.map(IsoDateInner)
203-
.map(|inner| Date::from_raw(inner, Iso))
203+
.map(|inner| Date {
204+
inner,
205+
calendar: Iso,
206+
})
204207
}
205208
}
206209

components/calendar/src/cal/japanese.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ impl Japanese {
120120
]);
121121

122122
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
123+
///
124+
/// <div class="stab unstable">
125+
/// 🚧 This method is considered unstable; it may change at any time, in breaking or non-breaking ways,
126+
/// including in SemVer minor releases. This requires the `unstable` Cargo feature.
127+
/// </div>
128+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
123129
pub fn try_new_unstable<D: DataProvider<CalendarJapaneseModernV1> + ?Sized>(
124130
provider: &D,
125131
) -> Result<Self, DataError> {
@@ -155,6 +161,12 @@ impl JapaneseExtended {
155161
]);
156162

157163
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
164+
///
165+
/// <div class="stab unstable">
166+
/// 🚧 This method is considered unstable; it may change at any time, in breaking or non-breaking ways,
167+
/// including in SemVer minor releases. This requires the `unstable` Cargo feature.
168+
/// </div>
169+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
158170
pub fn try_new_unstable<D: DataProvider<CalendarJapaneseExtendedV1> + ?Sized>(
159171
provider: &D,
160172
) -> Result<Self, DataError> {
@@ -440,12 +452,12 @@ impl Date<Japanese> {
440452
year: i32,
441453
month: u8,
442454
day: u8,
443-
japanese_calendar: A,
455+
calendar: A,
444456
) -> Result<Date<A>, DateError> {
445-
let inner = japanese_calendar
457+
let inner = calendar
446458
.as_calendar()
447459
.new_japanese_date_inner(era, year, month, day)?;
448-
Ok(Date::from_raw(inner, japanese_calendar))
460+
Ok(Date { inner, calendar })
449461
}
450462
}
451463

@@ -488,13 +500,13 @@ impl Date<JapaneseExtended> {
488500
year: i32,
489501
month: u8,
490502
day: u8,
491-
japanext_calendar: A,
503+
calendar: A,
492504
) -> Result<Date<A>, DateError> {
493-
let inner = japanext_calendar
505+
let inner = calendar
494506
.as_calendar()
495507
.0
496508
.new_japanese_date_inner(era, year, month, day)?;
497-
Ok(Date::from_raw(inner, japanext_calendar))
509+
Ok(Date { inner, calendar })
498510
}
499511
}
500512

components/calendar/src/cal/julian.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ impl Date<Julian> {
230230
pub fn try_new_julian(year: i32, month: u8, day: u8) -> Result<Date<Julian>, RangeError> {
231231
ArithmeticDate::new_from_ordinals(year, month, day)
232232
.map(JulianDateInner)
233-
.map(|inner| Date::from_raw(inner, Julian))
233+
.map(|inner| Date {
234+
inner,
235+
calendar: Julian,
236+
})
234237
}
235238
}
236239

components/calendar/src/cal/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub use roc::Roc;
3939
pub use crate::any_calendar::{AnyCalendar, AnyCalendarKind};
4040

4141
/// Internal scaffolding types
42+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
4243
pub mod scaffold {
4344
/// Trait marking other traits that are considered unstable and should not generally be
4445
/// implemented outside of the calendar crate.

components/calendar/src/cal/persian.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,10 @@ impl Date<Persian> {
221221
pub fn try_new_persian(year: i32, month: u8, day: u8) -> Result<Date<Persian>, RangeError> {
222222
ArithmeticDate::new_from_ordinals(year, month, day)
223223
.map(PersianDateInner)
224-
.map(|inner| Date::from_raw(inner, Persian))
224+
.map(|inner| Date {
225+
inner,
226+
calendar: Persian,
227+
})
225228
}
226229
}
227230

0 commit comments

Comments
 (0)