File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,16 @@ impl<T: ?Sized> *const T {
4848 self as _
4949 }
5050
51+ /// Changes constness without changing the type.
52+ ///
53+ /// This is a bit safer than `as` because it wouldn't silently change the type if the code is
54+ /// refactored.
55+ #[ unstable( feature = "ptr_const_cast" , issue = "92675" ) ]
56+ #[ rustc_const_unstable( feature = "ptr_const_cast" , issue = "92675" ) ]
57+ pub const fn as_mut ( self ) -> * mut T {
58+ self as _
59+ }
60+
5161 /// Casts a pointer to its raw bits.
5262 ///
5363 /// This is equivalent to `as usize`, but is more specific to enhance readability.
Original file line number Diff line number Diff line change @@ -47,6 +47,20 @@ impl<T: ?Sized> *mut T {
4747 self as _
4848 }
4949
50+ /// Changes constness without changing the type.
51+ ///
52+ /// This is a bit safer than `as` because it wouldn't silently change the type if the code is
53+ /// refactored.
54+ ///
55+ /// While not strictly required (`*mut T` coerces to `*const T`), this is provided for symmetry
56+ /// with `as_mut()` on `*const T` and may have documentation value if used instead of implicit
57+ /// coercion.
58+ #[ unstable( feature = "ptr_const_cast" , issue = "92675" ) ]
59+ #[ rustc_const_unstable( feature = "ptr_const_cast" , issue = "92675" ) ]
60+ pub const fn as_const ( self ) -> * const T {
61+ self as _
62+ }
63+
5064 /// Casts a pointer to its raw bits.
5165 ///
5266 /// This is equivalent to `as usize`, but is more specific to enhance readability.
You can’t perform that action at this time.
0 commit comments