Function konst::ptr::as_ref

source ·
pub const unsafe fn as_ref<'a, T: ?Sized>(ptr: *const T) -> Option<&'a T>
Expand description

Const equivalent of <*const>::as_ref

§Safety

This function has the same safety requirements as <*const T>::as_ref

§Example

use konst::ptr;

use core::ptr::null;

const NONE: Option<&u8> = unsafe{ ptr::as_ref(null()) };
const SOME: Option<&u8> = unsafe{ ptr::as_ref(&100) };

assert_eq!(NONE, None);
assert_eq!(SOME, Some(&100));