-
Notifications
You must be signed in to change notification settings - Fork 174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create BoundProvider, NeoFormatter, and TypedNeoFormatter #4877
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some preliminary thoughts
/// The specific type does not support this field | ||
TypeTooNarrow(Field), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not clear which "type" is too "narrow". I think this is the same as UnsupportedField
, we should just update the doc string to say "The formatter doesn't support this field". I don't think we need to differentiate between ICU4X not supporting a field, and a selected formatter not supporting a field, ICU4X is just the union of all formatters, but this union could grow.
_calendar: PhantomData<C>, | ||
} | ||
|
||
pub trait DateTimeNamesMarker { | ||
type YearNames: MaybePayload<YearNamesV1<'static>> + fmt::Debug; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: put the Debug
bound on MaybePayload
.
year_symbols: OptionalNames<(), R::YearNames>, | ||
month_symbols: OptionalNames<fields::Month, R::MonthNames>, | ||
weekday_symbols: OptionalNames<fields::Weekday, R::WeekdayNames>, | ||
dayperiod_symbols: OptionalNames<(), R::DayPeriodNames>, | ||
// TODO(#4340): Make the FixedDecimalFormatter optional | ||
fixed_decimal_formatter: Option<FixedDecimalFormatter>, | ||
week_calculator: Option<WeekCalculator>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
week_calculator is also not needed for time formatting, can we store the raw payload as a MaybePayload
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little harder because it is cross-crate. Added a TODO.
components/datetime/src/neo.rs
Outdated
.map_err(LoadError::Data)?; | ||
let mut names = RawDateTimeNames::new_without_fixed_decimal_formatter(); | ||
names | ||
.load_for_pattern::<<R::Data as TypedNeoSkeletonData<C>>::YearNamesV1Marker, <R::Data as TypedNeoSkeletonData<C>>::MonthNamesV1Marker, <R::Data as NeoSkeletonCommonData>::WeekdayNamesV1Marker, <R::Data as NeoSkeletonCommonData>::DayPeriodNamesV1Marker>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is a LoadError::MissingNames
actually possible here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is narrowed down to only WeekCalculator and FixedDecimalFormatter now. I added a TODO to give those the same treatment I gave the others, and then we can eliminate this error variant.
(cherry picked from commit 729870d)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed design in meeting today, things made sense. would be nice to further document most of the traits here by their purpose and what they interact with (if not done already)
@@ -81,86 +83,6 @@ pub trait CldrCalendar: InternalCldrCalendar { | |||
} | |||
} | |||
|
|||
#[cfg(feature = "experimental")] | |||
pub(crate) trait YearNamesV1Provider<M: DataMarker> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
components/datetime/src/calendar.rs
Outdated
/// A collection of marker types associated with all calendars. | ||
#[allow(private_bounds)] // sealed | ||
#[cfg(any(feature = "datagen", feature = "experimental"))] | ||
pub trait CalMarkers<M>: Sealed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: this trait feels backwards to me but i also think this is the best way to do this.
suggestion: more docs maybe, covering how it gets used?
+ DataProvider<RocDatePatternV1Marker> | ||
+ DataProvider<RocYearNamesV1Marker> | ||
+ DataProvider<RocMonthNamesV1Marker> | ||
+ DataProvider<<FullData as CalMarkers<YearNamesV1Marker>>::Buddhist> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: ew. but reasonable.
/// Unlike [`DataProvider`], the provider is bound to a specific key ahead of time. | ||
/// | ||
/// [`AnyMarker`]: crate::any::AnyMarker | ||
pub trait BoundDataProvider<M> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(have expressed opinions about docs here on the other PR, fine to have this land as is and then do a followup)
Part of #1317
This PR adds
TypedNeoFormatter
andNeoFormatter
that use a type parameter to handle all datetime formatting.This PR is productive because:
Some notes:
NeverMarker
is used for the DataProvider bound, and()
is used for storage types.TypedNeoFormatter
(one for the calendar and one for the skeleton); happy for suggestions.Still draft for now because I need to make anycalendar compile. I know how to do it, it's just annoying.