-
Notifications
You must be signed in to change notification settings - Fork 185
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 icu_preferences util #4996
Add icu_preferences util #4996
Conversation
1360e40
to
c2640dc
Compare
This is ready for review. The deps in components have been cleaned up and documented, the util iteself is not yet well documented as I prefer to first get aligned on the API. |
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.
Looks good overall
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.
Not a full review yet, just spot-checking
Discussion notes:
|
pub fn into_single_subtag(self) -> Option<Subtag> { | ||
self.0.into_single() | ||
} |
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.
Discussion: I don't see a good reason to have a moving into_single_subtag
function since Subtag
is Copy
. Seems like as_single_subtag(&self)
would be fine.
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.
The value is that you don't need to copy even - you destruct into a single Subtag. Let me know if that convinces you, I'll replace it with as_single_subtag().copied()
otherwise.
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.
Maybe just make as_single_subtag
return Option<Subtag>
.
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.
Optional: rename the function to_single_subtag
.
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.
as_ -> Free -> borrowed -> borrowed
to_ -> Expensive -> borrowed -> borrowed
borrowed -> owned (non-Copy types)
owned -> owned (Copy types)
into_ -> Variable -> owned -> owned (non-Copy types)
We have:
as_single_subtag(&self) -> Option<&Subtag>
into_single_subtag(self) -> Option<Subtag>
I think as_
and into_
fit - to_
could work if source was Copy, but it's not, so passing it has to consume (to_
should take reference).
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.
Well it's arguable that it is working on Copy types because it returns Some if the thing is a single Subtag (Copy). But I don't feel strongly about this and it need not block the PR
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 checked that. The closest reference in Stdlib I could find it Cow
which has:
to_mut(&mut self) -> &mut <B as ToOwned>::Owned
into_owned(self) -> <B as ToOwned>::Owned
(vs. OSstring::to_owned(&mut self) -> T`.
The latter has also the following description:
Creates owned data from borrowed data, usually by cloning.
So my read is that to_
is meant to be expensive, it takes a borrowed value. Our case is cheap, it takes an owned value.
I agree that it's not a clear cut, but I don't take &self
and I don't clone. to_X(self) -> T
is only for primitive types such as f64::to_bits
.
I'll keep into_*
.
utils/preferences/src/extensions/unicode/keywords/dictionary_break.rs
Outdated
Show resolved
Hide resolved
utils/preferences/src/extensions/unicode/keywords/region_override.rs
Outdated
Show resolved
Hide resolved
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.
My comment last time was a "here and elsewhere" but the elsewhere didn't happen :)
No description provided.