Naming convention of as_borrowed #6027
Labels
2.0-breaking
Changes that are breaking API changes
needs-approval
One or more stakeholders need to approve proposal
S-small
Size: One afternoon (small bug fix or enhancement)
Milestone
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: