rust
                                
                                 rust copied to clipboard
                                
                                    rust copied to clipboard
                            
                            
                            
                        Tracking Issue for ptr_const_cast
Feature gate: #![feature(ptr_const_cast)]
This is a tracking issue for methods on pointers for casting constness without changing the type
Public API
impl<T: ?Sized> *const T {
    pub fn as_mut(self) -> *mut T;
}
impl<T: ?Sized> *mut T {
    pub fn as_const(self) -> *const T;
}
Steps / History
- [x] Implementation: #92657
- [ ] Final comment period (FCP)
- [ ] Stabilization PR
Unresolved Questions
- ~~*mut Talso already hasas_mut()which does something different and has a different signature, adding a mehod of the same name to*const Tcould be confusing, so maybe a better name should be used.cast_const/cast_mutwas suggested.~~ Resolved to usecast_*
I like this function (as it allows a codebase to avoid uses of as if they desire). I agree thta as_mut() could lead to some ambiguity, and cast_mut seems better to me. It's the most similar to cast, so having a similar name seems correct.
As noted in the documentation, a cast_const method isn't strictly necessary, but could be nice for symmetry's sake.
I'm starting to like cast_ naming as it seems to be a bit more readable too. Will try to find the time for a PR. I don't mind anyone else doing it either. It's a trivial change anyway.
Once they're called cast_, I wonder if we should also add a type parameter like the existing cast method, so you don't have to double up .cast().cast_const() etc.
(However, they currently document that as an explicit feature, not changing the type.)
@cuviper yes, not changing the type is the main point because it protects against refactors. You can already do both with as.
Shall we rename these to cast_*, and also stabilize them?
@rfcbot merge
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:
- [x] @Amanieu
- [ ] @BurntSushi
- [x] @dtolnay
- [x] @joshtriplett
- [x] @m-ou-se
- [x] @yaahc
No concerns currently listed.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
See this document for info about what commands tagged team members can give me.
:bell: This is now entering its final comment period, as per the review above. :bell:
The final comment period, with a disposition to merge, as per the review above, is now complete.
As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.
This will be merged soon.