pub const fn new<T: ?Sized>(ptr: *mut T) -> Option<NonNull<T>>
Expand description
Const equivalent of NonNull::new
.
ยงExample
use konst::ptr::nonnull;
use core::ptr::{NonNull, null_mut};
const NONE: Option<NonNull<u8>> = nonnull::new(null_mut());
const SOME: Option<NonNull<u8>> = nonnull::new(&100 as *const _ as *mut _);
assert!(NONE.is_none());
assert_eq!(SOME.map(|x|unsafe{*x.as_ptr()}), Some(100));