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 total_cmp helper functions to icu_locid types and DataLocale #4608

Merged
merged 7 commits into from
Mar 6, 2024

Conversation

sffc
Copy link
Member

@sffc sffc commented Feb 14, 2024

We do not implement Ord on Locale or LanguageIdentifier because there are multiple possible orderings, and we did not want to privilege one ordering over another (see #1215).

We export a strict_cmp function that compares the receiver with a byte array. However, we do not export a function that compares the receiver to another object of the same type. This had led to issues such as #3588. I also stumbled across this today when trying to make a BTreeSet of locales.

In order to serve this use case, I added the following function to the types that needed it:

    /// Returns an ordering suitable for use in [`BTreeSet`].
    ///
    /// The ordering may or may not be equivalent to string ordering, and it
    /// may or may not be stable across ICU4X releases.
    ///
    /// [`BTreeSet`]: alloc::collections::BTreeSet
    pub fn total_cmp(&self, other: &Self) -> Ordering

This gives us flexibility moving forward to tweak the impl or add additional comparison functions producing different orderings.

@sffc sffc requested review from robertbastian and removed request for nciric February 14, 2024 02:25
@sffc sffc requested a review from a team as a code owner February 14, 2024 02:44
Manishearth
Manishearth previously approved these changes Feb 14, 2024
pub(crate) fn as_tuple(
&self,
) -> (
(&unicode::Attributes, &unicode::Keywords),
Copy link
Member

Choose a reason for hiding this comment

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

...wow that's a type

@Manishearth
Copy link
Member

not 100% convinced this is needed over FFI but it's a weak opinion

robertbastian
robertbastian previously approved these changes Feb 14, 2024
provider/core/src/request.rs Show resolved Hide resolved
zbraniecki
zbraniecki previously approved these changes Feb 27, 2024
Copy link
Member

@zbraniecki zbraniecki left a comment

Choose a reason for hiding this comment

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

I'd rephrase the comment. Instead of "may or may not be stable", we should say "we do not guarantee stability across versions".

@Manishearth Manishearth dismissed stale reviews from zbraniecki, robertbastian, and themself via e635305 March 6, 2024 10:14
@Manishearth Manishearth merged commit f5ee301 into unicode-org:main Mar 6, 2024
30 checks passed
@sffc sffc deleted the locale-structural-cmp branch March 6, 2024 13:02
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.

4 participants