-
Notifications
You must be signed in to change notification settings - Fork 225
[locale_core] Add extend
to Unicode Extensions
#7112
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
base: main
Are you sure you want to change the base?
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.
I think in general this is a good API. I would like @sffc at least to also stamp it.
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.
Seems fine but always concerned about any method named "extend" is the conflict with the std trait Extend https://doc.rust-lang.org/std/iter/trait.Extend.html
I think elsewhere we've called it extend_with_X to avoid the name clash
Hmm, I missed it here: https://docs.rs/icu/latest/icu/locale/preferences/struct.LocalePreferences.html#method.extend - which is what I wanted to shape it after. I looked at potentially using this trait, and:
Now that I reflect on it, I think I introduced the method on @Manishearth @sffc - what are your preferences here? |
Yeah if something is not collection-like, and won't ever implement the Extend trait, then it seems harmless to use a function named LocalePreferences (and Locale in general) are heterogenous collections, as in, you can't really turn them into iterators of something. So maybe Here's where I used https://docs.rs/litemap/latest/litemap/struct.LiteMap.html#method.extend_from_litemap |
@sffc what's your take on |
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.
Observation: Keywords
already implements iter(&self) -> impl Iterator<Item = (&Key, &Value)>
so it's already public that we consider it collection-like, so I think it's safest to not use a custom extend
function signature. However, I think it's overkill to use the trait. I suggest using the specific function names on Keywords and Attributes. However, since Extensions is heterogeneous, I don't think we need to use the special name there.
/// assert_eq!(kw, "ab-cd-ca-gregory-hc-h12".parse().unwrap()); | ||
/// ``` | ||
#[cfg(feature = "alloc")] | ||
pub fn extend(&mut self, other: Keywords) { |
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.
pub fn extend(&mut self, other: Keywords) { | |
pub fn extend_from_keywords(&mut self, other: Keywords) { |
/// assert_eq!(attrs, "foobar-foobaz-fooqux".parse().unwrap()); | ||
/// ``` | ||
#[cfg(feature = "alloc")] | ||
pub fn extend(&mut self, other: Attributes) { |
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.
pub fn extend(&mut self, other: Attributes) { | |
pub fn extend_from_attributes(&mut self, other: Attributes) { |
I also think it's overkill to use the trait. |
This change aligns with how
Preferences::extend
works and will be used in regional preferences merges inhost_info
.