pub const unsafe fn as_ref<'a, T: ?Sized>(ptr: NonNull<T>) -> &'a T
Expand description
Const equivalent of NonNull::as_ref
.
§Safety
This has the same safety requirements as NonNull::as_ref
§Example
use konst::ptr::nonnull;
use core::{
ptr::NonNull,
marker::PhantomData,
};
const A: NonNull<u8> = nonnull::from_ref(&3);
const A_REF: &u8 = unsafe{ nonnull::as_ref(A) };
assert_eq!(A_REF, &3);
const B: NonNull<str> = nonnull::from_ref("hello");
const B_REF: &str = unsafe{ nonnull::as_ref(B) };
assert_eq!(B_REF, "hello");