Function deref

Source
pub const unsafe fn deref<'a, T: ?Sized>(ptr: *const T) -> &'a T
Expand description

Const equivalent of &*raw_pointer.

§Safety

This function has the safety requirements of <*const>::as_ref, in addition to requiring that ptr is not null.

§Example

use konst::ptr;

const F: &u8 = unsafe{ ptr::deref("foo".as_ptr()) };
assert_eq!(F, &b'f');

const BAR: &[u8; 3] = unsafe{ ptr::deref("bar".as_ptr().cast::<[u8; 3]>()) };
assert_eq!(BAR, b"bar");