Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,13 @@ impl<T: ?Sized> *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<U>(self) -> *const U {
self as _
}

/// Returns `None` if the pointer is null, or else returns a reference to
/// the value wrapped in `Some`.
///
Expand Down Expand Up @@ -1593,6 +1600,13 @@ impl<T: ?Sized> *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<U>(self) -> *mut U {
self as _
}

/// Returns `None` if the pointer is null, or else returns a reference to
/// the value wrapped in `Some`.
///
Expand Down