-
Notifications
You must be signed in to change notification settings - Fork 20
Implement AsRef, Borrow for std::cell::Ref, RefMut #215
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
Comments
We discussed this proposal in today's standard library API meeting. Those present were ambivalent about whether adding these impls would really be an improvement or not. Having a better motivation written up would have been helpful, ideally with a link to real-world code showing that not having these impls causes friction, and what the code today is doing instead to work around it. The current ACP's motivation probably applies equally to quite a few other types — for example MutexGuard came up as a type that implements Deref but not AsRef nor Borrow. Would it be possible to get a list of all other Deref-implementing standard library types which are equally well motivated for getting a new AsRef and Borrow impl? We'd be interested to get a PR adding them all, and put it through Crater all at once. If that goes smoothly, we're probably fine going forward with this. AsRef in particular is the most likely to cause widespread breakage. For It's possible that something like |
I expanded the motivation above (with fixed code). Note: this motivation applies only to the |
We could restrict this proposal to
Existing impls are:
Possibly missing impls are:
I'm not sure about I skipped |
Thank you for the effort put into the summary, that provided context for our discussion in the last libs-API meeting. We came to the conclusion that it would be possible to implement Additionally the main use of the Based on this we decided to reject this proposal. |
Proposal
Problem statement
Implement
AsRef
,Borrow
forstd::cell::Ref
,RefMut
.Motivation, use-cases
Why? Because we can. This is what
AsRef
andBorrow
are for? (More generally: any impl ofDeref
should implAsRef
too?)Further motivation is that it appears we should be able to do the following.
However, since
std::cell::Ref
does not implementBorrow<str>
, we need<MyCell as Foo>::Ref
to be a wrapper aroundstd::cell::Ref
like this:Here,
MyStrRef
is boilerplate which should not be necessary.Solution
rust-lang/rust#101981
The text was updated successfully, but these errors were encountered: