Skip to content
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

Add field set options constructor #5556

Merged
merged 9 commits into from
Sep 19, 2024
Merged

Add field set options constructor #5556

merged 9 commits into from
Sep 19, 2024

Conversation

sffc
Copy link
Member

@sffc sffc commented Sep 18, 2024

#1317
#5269

This code now works. Notice the lack of spaceships.

let formatter =
    TypedNeoFormatter::try_new2(
        &locale!("es-MX").into(),
        NeoYearMonthDayMarker::with_length(NeoSkeletonLength::Long),
    )
    .unwrap();

assert_try_writeable_eq!(
    formatter.format(&Date::try_new_gregorian_date(2023, 12, 20).unwrap()),
    "20 de diciembre de 2023"
);

The things formerly called "datetime markers" are now options bags. Example:

https://icu4x-pr-artifacts.storage.googleapis.com/gha/dd9ff1a4d063806210470658595a9055ddfe058d/rustdoc/icu_datetime/neo_marker/struct.NeoYearMonthMarker.html

Obviously I intend to change the names of things. I have not applied any of the naming conventions we've discussed. I'm only implementing the new constructor style that I think we agreed on in #5269.

@sffc sffc changed the title Fsetoptions Add field set options constructor Sep 18, 2024
@sffc sffc marked this pull request as ready for review September 19, 2024 00:16
@sffc
Copy link
Member Author

sffc commented Sep 19, 2024

This isn't "completely done" but it should pass CI and I'd like a review before I add the remaining impls

@sffc sffc requested review from robertbastian and removed request for zbraniecki and nordzilla September 19, 2024 00:17
Manishearth
Manishearth previously approved these changes Sep 19, 2024
/// );
/// ```
#[cfg(feature = "compiled_data")]
pub fn try_new2(locale: &DataLocale, options: FSet) -> Result<Self, LoadError>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (nb): don't like this name, but we can revisit later

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intend to replace the old try_new with the new signature

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sgtm

input_day_of_week = $day_of_week_yesno:ident,
input_day_of_year = $day_of_year_yesno:ident,
input_any_calendar_kind = $any_calendar_kind_yesno:ident,
$(years = $years_yes:ident,)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: document how the yesno stuff works for callers

@@ -1365,72 +1365,75 @@ macro_rules! datetime_marker_helper {
(@years/typed, yes) => {
C::YearNamesV1Marker
};
(@years/typed, no) => {
(@years/typed,) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I have no idea what the no means, consider using something more descriptive than yes/no for this argument.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did add more docs yesterday, but not to this macro, which is two-layers internal. I'll keep adding docs as I refactor and clean up this file.

/// Generates an impl of [`NeoGetField`]
macro_rules! impl_get_field {
($type:path, never) => {
impl NeoGetField<NeverField> for $type {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using NeoGetField for both fields (i.e. data) and options? I think that's confusing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's using the same trait because the signature is what I need and it is reasonably close semantically. I am happy to rename the trait. As noted previously, I see the trait like AsRef except that it returns by value instead of by reference.

@Manishearth

/// use writeable::assert_try_writeable_eq;
///
/// let formatter =
/// TypedNeoFormatter::try_new2(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if you just replaced the current constructors, then the docs would actually be a diff to what we have now. I have no idea what we have now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there are still some tests that need fixing.

I'm quite open to doing a gradual migration here. We have to take a holistic look at this crate in the end anyway.

@sffc sffc merged commit 02153c6 into unicode-org:main Sep 19, 2024
28 checks passed
@sffc sffc deleted the fsetoptions branch September 19, 2024 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants