We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
cast<U>() -> NonNull<U>
NonNull<T>
1 parent 6461c9b commit b8ffc8aCopy full SHA for b8ffc8a
src/libcore/ptr.rs
@@ -2553,6 +2553,14 @@ impl<T: ?Sized> NonNull<T> {
2553
pub unsafe fn as_mut(&mut self) -> &mut T {
2554
&mut *self.as_ptr()
2555
}
2556
+
2557
+ /// Cast to a pointer of another type
2558
+ #[unstable(feature = "nonnull_cast", issue = "47653")]
2559
+ pub fn cast<U>(self) -> NonNull<U> {
2560
+ unsafe {
2561
+ NonNull::new_unchecked(self.as_ptr() as *mut U)
2562
+ }
2563
2564
2565
2566
#[stable(feature = "nonnull", since = "1.25.0")]
0 commit comments