diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index a41be4269d504..6355bcdcab2fa 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -974,6 +974,13 @@ impl *const T { (self as *const u8) == null() } + /// Cast to a pointer to a different type + #[unstable(feature = "ptr_cast", issue = "60602")] + #[inline] + pub const fn cast(self) -> *const U { + self as _ + } + /// Returns `None` if the pointer is null, or else returns a reference to /// the value wrapped in `Some`. /// @@ -1593,6 +1600,13 @@ impl *mut T { (self as *mut u8) == null_mut() } + /// Cast to a pointer to a different type + #[unstable(feature = "ptr_cast", issue = "60602")] + #[inline] + pub const fn cast(self) -> *mut U { + self as _ + } + /// Returns `None` if the pointer is null, or else returns a reference to /// the value wrapped in `Some`. ///