Skip to content

Commit b15d9e1

Browse files
authored
Fix reexport documentation to be clearer when things are reexports (#6372)
Also moves public/stable types TimeZone and TimeZoneVariant out of the provider module, turning the reexport into the other direction. Even with `doc(no_inline)`, I'm more comfortable with the provider module only containing unstable types and reexports of stable types. Fixes #6240 <!-- Thank you for your pull request to ICU4X! Reminder: try to use [Conventional Comments](https://conventionalcomments.org/) to make comments clearer. Please see https://github.com/unicode-org/icu4x/blob/main/CONTRIBUTING.md for general information on contributing to ICU4X. -->
1 parent a1555e5 commit b15d9e1

File tree

10 files changed

+146
-134
lines changed

10 files changed

+146
-134
lines changed

components/calendar/src/date.rs

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ impl<C> Deref for Ref<'_, C> {
8989

9090
/// A date for a given calendar.
9191
///
92+
/// **The primary definition of this type is in the [`icu_calendar`](docs.rs/icu_calendar) crate. Other ICU4X crates re-export it for convenience.**
93+
///
9294
/// This can work with wrappers around [`Calendar`] types,
9395
/// e.g. `Rc<C>`, via the [`AsCalendar`] trait.
9496
///

components/datetime/src/lib.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -137,26 +137,14 @@ pub mod preferences {
137137
}
138138

139139
/// Types that can be fed to [`DateTimeFormatter`]/[`FixedCalendarDateTimeFormatter`].
140+
///
141+
/// This module contains re-exports from the [`icu_calendar`] and [`icu_time`] crates.
140142
pub mod input {
141-
/// **This is a reexport of a type in [`icu_calendar`]**.
142-
#[doc = "\n"] // prevent autoformatting
143143
pub use icu_calendar::Date;
144-
/// **This is a reexport of a type in [`icu_time`]**.
145-
#[doc = "\n"] // prevent autoformatting
146144
pub use icu_time::zone::UtcOffset;
147-
/// **This is a reexport of a type in [`icu_time`]**.
148-
#[doc = "\n"] // prevent autoformatting
149145
pub use icu_time::DateTime;
150-
/// **This is a reexport of a type in [`icu_time`]**.
151-
#[doc = "\n"] // prevent autoformatting
152146
pub use icu_time::Time;
153-
/// **This is a reexport of a type in [`icu_time`]**.
154-
#[doc = "\n"] // prevent autoformatting
155147
pub use icu_time::TimeZone;
156-
/// **This is a reexport of a type in [`icu_time`]**.
157-
#[doc = "\n"] // prevent autoformatting
158148
pub use icu_time::TimeZoneInfo;
159-
/// **This is a reexport of a type in [`icu_time`]**.
160-
#[doc = "\n"] // prevent autoformatting
161149
pub use icu_time::ZonedDateTime;
162150
}

components/decimal/src/lib.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,12 @@ pub mod preferences {
133133
}
134134

135135
/// Types that can be fed to [`DecimalFormatter`] and their utilities
136+
///
137+
/// This module contains re-exports from the [`fixed_decimal`] crate.
136138
pub mod input {
137-
/// **This is a reexport of a type in [`fixed_decimal`]**.
138-
#[doc = "\n"] // prevent autoformatting
139139
pub use fixed_decimal::Decimal;
140-
/// **This is a reexport of a type in [`fixed_decimal`]**.
141-
///
142-
/// This type can be made available with the `"ryu"` Cargo feature.
143-
#[doc = "\n"] // prevent autoformatting
144140
#[cfg(feature = "ryu")]
145141
pub use fixed_decimal::FloatPrecision;
146-
/// **This is a reexport of a type in [`fixed_decimal`]**.
147-
#[doc = "\n"] // prevent autoformatting
148142
pub use fixed_decimal::SignDisplay;
149143
}
150144

components/time/src/provider/mod.rs

+4-107
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
1818
use crate::Time;
1919
use calendrical_calculations::rata_die::RataDie;
20-
use core::ops::Deref;
2120
use icu_calendar::{Date, Iso};
21+
#[cfg(feature = "datagen")]
2222
use icu_provider::prelude::*;
23-
use tinystr::TinyAsciiStr;
2423
use zerovec::maps::ZeroMapKV;
25-
use zerovec::ule::{AsULE, ULE};
24+
use zerovec::ule::AsULE;
2625
use zerovec::{ZeroMap2d, ZeroSlice, ZeroVec};
2726

27+
pub use crate::zone::ule::TimeZoneVariantULE;
28+
pub use crate::zone::TimeZone;
2829
pub mod iana;
2930
pub mod windows;
3031

@@ -62,110 +63,6 @@ pub const MARKERS: &[DataMarkerInfo] = &[
6263
TimeZoneOffsetsV1::INFO,
6364
];
6465

65-
/// A CLDR time zone identity.
66-
///
67-
/// This can be created directly from BCP-47 strings, or it can be parsed from IANA IDs.
68-
///
69-
/// CLDR uses difference equivalence classes than IANA. For example, `Europe/Oslo` is
70-
/// an alias to `Europe/Berlin` in IANA (because they agree since 1970), but these are
71-
/// different identities in CLDR, as we want to be able to say "Norway Time" and
72-
/// "Germany Time". On the other hand `Europe/Belfast` and `Europe/London` are the same
73-
/// CLDR identity ("UK Time").
74-
///
75-
/// ```
76-
/// use icu::time::zone::{IanaParser, TimeZone};
77-
/// use tinystr::tinystr;
78-
///
79-
/// let parser = IanaParser::new();
80-
/// assert_eq!(parser.parse("Europe/Oslo"), TimeZone(tinystr!(8, "noosl")));
81-
/// assert_eq!(
82-
/// parser.parse("Europe/Berlin"),
83-
/// TimeZone(tinystr!(8, "deber"))
84-
/// );
85-
/// assert_eq!(
86-
/// parser.parse("Europe/Belfast"),
87-
/// TimeZone(tinystr!(8, "gblon"))
88-
/// );
89-
/// assert_eq!(
90-
/// parser.parse("Europe/London"),
91-
/// TimeZone(tinystr!(8, "gblon"))
92-
/// );
93-
/// ```
94-
#[repr(transparent)]
95-
#[derive(Debug, Clone, Copy, Eq, Ord, PartialEq, PartialOrd, yoke::Yokeable, ULE, Hash)]
96-
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
97-
#[cfg_attr(feature = "datagen", databake(path = icu_time::provider))]
98-
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
99-
pub struct TimeZone(pub TinyAsciiStr<8>);
100-
101-
impl TimeZone {
102-
/// The synthetic `Etc/Unknown` time zone.
103-
///
104-
/// This is the result of parsing unknown zones. It's important that such parsing does not
105-
/// fail, as new zones are added all the time, and ICU4X might not be up to date.
106-
pub const fn unknown() -> Self {
107-
Self(tinystr::tinystr!(8, "unk"))
108-
}
109-
}
110-
111-
impl Deref for TimeZone {
112-
type Target = TinyAsciiStr<8>;
113-
114-
fn deref(&self) -> &Self::Target {
115-
&self.0
116-
}
117-
}
118-
119-
impl AsULE for TimeZone {
120-
type ULE = Self;
121-
122-
#[inline]
123-
fn to_unaligned(self) -> Self::ULE {
124-
self
125-
}
126-
127-
#[inline]
128-
fn from_unaligned(unaligned: Self::ULE) -> Self {
129-
unaligned
130-
}
131-
}
132-
133-
impl<'a> zerovec::maps::ZeroMapKV<'a> for TimeZone {
134-
type Container = ZeroVec<'a, TimeZone>;
135-
type Slice = ZeroSlice<TimeZone>;
136-
type GetType = TimeZone;
137-
type OwnedType = TimeZone;
138-
}
139-
140-
/// A time zone variant, such as Standard Time, or Daylight/Summer Time.
141-
///
142-
/// This should not generally be constructed by client code. Instead, use
143-
/// * [`TimeZoneVariant::from_rearguard_isdst`]
144-
/// * [`TimeZoneInfo::infer_zone_variant`](crate::TimeZoneInfo::infer_zone_variant)
145-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
146-
#[zerovec::make_ule(TimeZoneVariantULE)]
147-
#[repr(u8)]
148-
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
149-
#[cfg_attr(feature = "datagen", databake(path = icu_time))]
150-
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
151-
#[non_exhaustive]
152-
pub enum TimeZoneVariant {
153-
/// The variant corresponding to `"standard"` in CLDR.
154-
///
155-
/// The semantics vary from time zone to time zone. The time zone display
156-
/// name of this variant may or may not be called "Standard Time".
157-
///
158-
/// This is the variant with the lower UTC offset.
159-
Standard = 0,
160-
/// The variant corresponding to `"daylight"` in CLDR.
161-
///
162-
/// The semantics vary from time zone to time zone. The time zone display
163-
/// name of this variant may or may not be called "Daylight Time".
164-
///
165-
/// This is the variant with the higher UTC offset.
166-
Daylight = 1,
167-
}
168-
16966
/// Storage type for storing UTC offsets as eights of an hour.
17067
pub type EighthsOfHourOffset = i8;
17168
/// Storage type for storing `(Date<Iso>, Time)`.

components/time/src/types.rs

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ dt_unit!(
118118

119119
/// A representation of a time in hours, minutes, seconds, and nanoseconds
120120
///
121+
/// **The primary definition of this type is in the [`icu_time`](docs.rs/icu_time) crate. Other ICU4X crates re-export it for convenience.**
122+
///
121123
/// This type supports the range [00:00:00.000000000, 23:59:60.999999999].
122124
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
123125
#[allow(clippy::exhaustive_structs)] // this type is stable
@@ -168,6 +170,8 @@ impl Time {
168170
}
169171

170172
/// A date and time for a given calendar.
173+
///
174+
/// **The primary definition of this type is in the [`icu_time`](docs.rs/icu_time) crate. Other ICU4X crates re-export it for convenience.**
171175
#[derive(Debug, PartialEq, Eq)]
172176
#[allow(clippy::exhaustive_structs)] // this type is stable
173177
pub struct DateTime<A: AsCalendar> {
@@ -178,6 +182,8 @@ pub struct DateTime<A: AsCalendar> {
178182
}
179183

180184
/// A date and time for a given calendar, local to a specified time zone.
185+
///
186+
/// **The primary definition of this type is in the [`icu_time`](docs.rs/icu_time) crate. Other ICU4X crates re-export it for convenience.**
181187
#[derive(Debug, PartialEq, Eq)]
182188
#[allow(clippy::exhaustive_structs)] // this type is stable
183189
pub struct ZonedDateTime<A: AsCalendar, Z> {

components/time/src/zone/mod.rs

+118-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ mod offset;
8888
pub mod windows;
8989

9090
#[doc(inline)]
91-
pub use crate::provider::{TimeZone, TimeZoneVariant};
9291
pub use offset::InvalidOffsetError;
9392
pub use offset::UtcOffset;
9493
pub use offset::VariantOffsets;
@@ -102,7 +101,12 @@ pub use windows::WindowsParser;
102101

103102
use crate::{scaffold::IntoOption, Time};
104103
use core::fmt;
104+
use core::ops::Deref;
105105
use icu_calendar::{Date, Iso};
106+
use icu_provider::prelude::yoke;
107+
use tinystr::TinyAsciiStr;
108+
use zerovec::ule::{AsULE, ULE};
109+
use zerovec::{ZeroSlice, ZeroVec};
106110

107111
/// Time zone data model choices.
108112
pub mod models {
@@ -158,7 +162,120 @@ pub mod models {
158162
}
159163
}
160164

165+
/// A CLDR time zone identity.
166+
///
167+
/// **The primary definition of this type is in the [`icu_time`](docs.rs/icu_time) crate. Other ICU4X crates re-export it for convenience.**
168+
///
169+
/// This can be created directly from BCP-47 strings, or it can be parsed from IANA IDs.
170+
///
171+
/// CLDR uses difference equivalence classes than IANA. For example, `Europe/Oslo` is
172+
/// an alias to `Europe/Berlin` in IANA (because they agree since 1970), but these are
173+
/// different identities in CLDR, as we want to be able to say "Norway Time" and
174+
/// "Germany Time". On the other hand `Europe/Belfast` and `Europe/London` are the same
175+
/// CLDR identity ("UK Time").
176+
///
177+
/// ```
178+
/// use icu::time::zone::{IanaParser, TimeZone};
179+
/// use tinystr::tinystr;
180+
///
181+
/// let parser = IanaParser::new();
182+
/// assert_eq!(parser.parse("Europe/Oslo"), TimeZone(tinystr!(8, "noosl")));
183+
/// assert_eq!(
184+
/// parser.parse("Europe/Berlin"),
185+
/// TimeZone(tinystr!(8, "deber"))
186+
/// );
187+
/// assert_eq!(
188+
/// parser.parse("Europe/Belfast"),
189+
/// TimeZone(tinystr!(8, "gblon"))
190+
/// );
191+
/// assert_eq!(
192+
/// parser.parse("Europe/London"),
193+
/// TimeZone(tinystr!(8, "gblon"))
194+
/// );
195+
/// ```
196+
#[repr(transparent)]
197+
#[derive(Debug, Clone, Copy, Eq, Ord, PartialEq, PartialOrd, yoke::Yokeable, ULE, Hash)]
198+
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
199+
#[cfg_attr(feature = "datagen", databake(path = icu_time))]
200+
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
201+
#[allow(clippy::exhaustive_structs)] // This is a stable newtype
202+
pub struct TimeZone(pub TinyAsciiStr<8>);
203+
204+
impl TimeZone {
205+
/// The synthetic `Etc/Unknown` time zone.
206+
///
207+
/// This is the result of parsing unknown zones. It's important that such parsing does not
208+
/// fail, as new zones are added all the time, and ICU4X might not be up to date.
209+
pub const fn unknown() -> Self {
210+
Self(tinystr::tinystr!(8, "unk"))
211+
}
212+
}
213+
214+
/// This module exists so we can cleanly reexport TimeZoneVariantULE from the provider module, whilst retaining a public stable TimeZoneVariant type.
215+
pub(crate) mod ule {
216+
/// A time zone variant, such as Standard Time, or Daylight/Summer Time.
217+
///
218+
/// This should not generally be constructed by client code. Instead, use
219+
/// * [`TimeZoneVariant::from_rearguard_isdst`]
220+
/// * [`TimeZoneInfo::infer_zone_variant`](crate::TimeZoneInfo::infer_zone_variant)
221+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
222+
#[zerovec::make_ule(TimeZoneVariantULE)]
223+
#[repr(u8)]
224+
#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
225+
#[cfg_attr(feature = "datagen", databake(path = icu_time))]
226+
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
227+
#[non_exhaustive]
228+
pub enum TimeZoneVariant {
229+
/// The variant corresponding to `"standard"` in CLDR.
230+
///
231+
/// The semantics vary from time zone to time zone. The time zone display
232+
/// name of this variant may or may not be called "Standard Time".
233+
///
234+
/// This is the variant with the lower UTC offset.
235+
Standard = 0,
236+
/// The variant corresponding to `"daylight"` in CLDR.
237+
///
238+
/// The semantics vary from time zone to time zone. The time zone display
239+
/// name of this variant may or may not be called "Daylight Time".
240+
///
241+
/// This is the variant with the higher UTC offset.
242+
Daylight = 1,
243+
}
244+
}
245+
pub use ule::TimeZoneVariant;
246+
247+
impl Deref for TimeZone {
248+
type Target = TinyAsciiStr<8>;
249+
250+
fn deref(&self) -> &Self::Target {
251+
&self.0
252+
}
253+
}
254+
255+
impl AsULE for TimeZone {
256+
type ULE = Self;
257+
258+
#[inline]
259+
fn to_unaligned(self) -> Self::ULE {
260+
self
261+
}
262+
263+
#[inline]
264+
fn from_unaligned(unaligned: Self::ULE) -> Self {
265+
unaligned
266+
}
267+
}
268+
269+
impl<'a> zerovec::maps::ZeroMapKV<'a> for TimeZone {
270+
type Container = ZeroVec<'a, TimeZone>;
271+
type Slice = ZeroSlice<TimeZone>;
272+
type GetType = TimeZone;
273+
type OwnedType = TimeZone;
274+
}
275+
161276
/// A utility type that can hold time zone information.
277+
///
278+
/// **The primary definition of this type is in the [`icu_time`](docs.rs/icu_time) crate. Other ICU4X crates re-export it for convenience.**
162279
#[derive(Debug, PartialEq, Eq)]
163280
#[allow(clippy::exhaustive_structs)] // these four fields fully cover the needs of UTS 35
164281
pub struct TimeZoneInfo<Model: models::TimeZoneModel> {

components/time/src/zone/offset.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use zerovec::ZeroMap2d;
1919
pub struct InvalidOffsetError;
2020

2121
/// An offset from Coordinated Universal Time (UTC)
22+
///
23+
/// **The primary definition of this type is in the [`icu_time`](docs.rs/icu_time) crate. Other ICU4X crates re-export it for convenience.**
2224
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, PartialOrd, Ord)]
2325
pub struct UtcOffset(i32);
2426

utils/fixed_decimal/src/rounding.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,14 @@ pub enum RoundingIncrement {
141141
MultiplesOf25,
142142
}
143143

144-
/// Specifies the precision of a floating point value when constructing a FixedDecimal.
144+
/// Specifies the precision of a floating point value when constructing a Decimal.
145145
///
146-
/// IEEE 754 is a representation of a point on the number line. On the other hand, FixedDecimal
146+
/// **The primary definition of this type is in the [`fixed_decimal`](docs.rs/fixed_decimal) crate. Other ICU4X crates re-export it for convenience.**
147+
///
148+
/// IEEE 754 is a representation of a point on the number line. On the other hand, Decimal
147149
/// specifies not only the point on the number line but also the precision of the number to a
148150
/// specific power of 10. This enum augments a floating-point value with the additional
149-
/// information required by FixedDecimal.
151+
/// information required by Decimal.
150152
#[non_exhaustive]
151153
#[cfg(feature = "ryu")]
152154
#[derive(Debug, Clone, Copy)]
@@ -168,7 +170,7 @@ pub enum FloatPrecision {
168170

169171
/// Specify that the floating point number is precise to the maximum representable by IEEE.
170172
///
171-
/// This results in a FixedDecimal having enough digits to recover the original floating point
173+
/// This results in a Decimal having enough digits to recover the original floating point
172174
/// value, with no trailing zeros.
173175
RoundTrip,
174176
}

0 commit comments

Comments
 (0)