-
Notifications
You must be signed in to change notification settings - Fork 173
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 PluralRules::categories() function #789
Conversation
The categories() function returns an iterator over each PluralCategory supported by a PluralRules object that has been created with a given LanguageIdentifier and PluralRuleType. The categories are returned in alphabetical order. This is what is expected by browsers, and the same order that ICU4C returns.
Pull Request Test Coverage Report for Build ccaf8dbbffad13bb294add9fc627b049706079bb-PR-789
💛 - Coveralls |
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 looks good!
One nit left. I also defer to your judgement how to handle the ecma402 discussion and my opinion for the sake of this PR.
You can land it with the change, or without the change, I'm not blocking.
@@ -191,31 +191,33 @@ pub enum PluralCategory { | |||
impl PluralCategory { | |||
/// Returns an ordered iterator over variants of [`Plural Categories`]. | |||
/// | |||
/// Categories are returned in alphabetical order. | |||
/// |
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.
opinion
: as you recognized in your PR comment, there is a discussion about the order, and in particular I am in a bad position to review this change since I expressed a strong opinion there.
I want to stress that my opinion there is non-blocking and if the group will decide to go against my recommendation I will accept it and thus do not consider it blocking for this PR. Just a change that I disagree with to match a proposal that I disagree with.
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.
I vote to land this as-is and update it to reflect the decision in ECMA-402. I added tc39/ecma402#578 to the agenda for the July 1 meeting.
Yeah it makes sense as is, we can do the transform at the FFI layer. |
Codecov Report
@@ Coverage Diff @@
## main #789 +/- ##
==========================================
+ Coverage 75.48% 75.55% +0.06%
==========================================
Files 194 192 -2
Lines 12297 12312 +15
==========================================
+ Hits 9283 9302 +19
+ Misses 3014 3010 -4
Continue to review full report at Codecov.
|
Fixes #778
The categories() function returns an iterator over each
PluralCategory supported by a PluralRules object that
has been created with a given LanguageIdentifier and
PluralRuleType.
The categories are returned in alphabetical order.
This is what is expected by browsers, and the same order
that ICU4C returns.
See tc39/ecma402#578 for more info on the ordering.
@zbraniecki the above means I had to change the ordering in which the
PluralCategory::all()
function returns each category from numerical order to alphabetical order. This should have no impact on performance, since I doubt the numerical order is optimized for putting the most common category first (although that would be a really interesting and unlikely coincidence).EDIT: Clearly I hadn't read the latest on the tc39 issue that I linked above. I'm happy to go back to numerical ordering based on that conversation.
@Manishearth and @sffc I know we discussed returning a
struct
orarray
ofbool
for FFI reasons. I'm still happy to change it to this, but returning an iterator overPluralCategory
seemed, to me, to be the most clean, idiomatic and natural Rust way to write this function. This approach should also be no-alloc, since it returns an iterator of'static
references.I am wondering if we can keep it this way, and put the iterator's contents into whatever structure is easiest for the FFI in the FFI layer. Please let me know either way. I'm happy to change it here if what I'm proposing won't work, but I think that returning an array of booleans is a pretty poor Rust-level API. That would make it entirely up to documentation to know which ordering the booleans represent (i.e.
Few
should always be first).Lastly, I was unsure of whether to call this
categories()
orkeywords()
.Category
frequently in ICU4XI decided to go with
categories()
to match our usage in ICU4X.