-
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
Naming convention of as_borrowed #6027
Comments
I disagree, this is from a family of functions called Agree with the other two. |
Should the other Date functions be named The whole "wrap calendar in X" is not particularly meaningful to users. They don't care that it's specifically the calendar that gets wrapped. They just care that their Date has a cheap clone afterward. |
Hm, perhaps. I'm okay with as_rc + as_arc + as_borrowed. |
|
It changes the type from |
This is a classic "what it does vs why you should use it" type of conflict. "Wrap calendar in Arc" is technically correct, describing "what it does", but it doesn't say anything about why you would want to use it. Most people want this because they want something cloneable without a lifetime. The term "Arc" we can assume to me fairly well known by our clients, so "as_arc" seems maybe about right. |
@robertbastian likes |
@Manishearth says this is "not better, not worse" than I think it is slightly better because no one needs to know that it is the calendar being wrapped; they just want to know that they have a thing that is ref-counted so they can cheaply clone it. |
Related: #4393
We have a lot of
as_borrowed
and similar functions through ICU4X.We should try to be consistent with how these work. Here's what I propose:
as_borrowed
should return a Copy wrapper that contains a reference to self. Example signature:impl Foo { pub fn as_borrowed<'a>(&'a self) -> FooBorrowed<'a> {...} }
as_borrowed
should return it.impl AsRef
should return references.impl AsRef
is needed in a const context, it can be namedas_foo_ref
or some other appropriate name, but notas_borrowed
since that has meaning prescribed in point 1. It could take the shadow nameas_ref
if there is only one sensible return value.Examples of specific impact of this:
Date::wrap_calendar_in_ref()
should beDate::as_borrowed()
ZeroTrie::as_borrowed_slice()
should beZeroTrie::as_borrowed()
ZeroTrie::as_borrowed()
, which currently returns&ZeroTrie
, should beZeroTrie::as_ref()
But it seems that mostly we already do this. I just found these examples where we are inconsistent.
CC @Manishearth @robertbastian
The text was updated successfully, but these errors were encountered: