File tree 2 files changed +24
-0
lines changed
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 {
48
48
self as _
49
49
}
50
50
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
+
51
61
/// Casts a pointer to its raw bits.
52
62
///
53
63
/// 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 {
47
47
self as _
48
48
}
49
49
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
+
50
64
/// Casts a pointer to its raw bits.
51
65
///
52
66
/// 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