Add an unstable cast<U>() -> NonNull<U>
method to NonNull<T>
.
This is less verbose than going through raw pointers to cast with `as`.
This commit is contained in:
parent
6461c9bdd3
commit
b8ffc8a3d8
1 changed files with 8 additions and 0 deletions
|
@ -2553,6 +2553,14 @@ impl<T: ?Sized> NonNull<T> {
|
|||
pub unsafe fn as_mut(&mut self) -> &mut T {
|
||||
&mut *self.as_ptr()
|
||||
}
|
||||
|
||||
/// Cast to a pointer of another type
|
||||
#[unstable(feature = "nonnull_cast", issue = "47653")]
|
||||
pub fn cast<U>(self) -> NonNull<U> {
|
||||
unsafe {
|
||||
NonNull::new_unchecked(self.as_ptr() as *mut U)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
|
|
Loading…
Reference in a new issue