Function konst::ptr::nonnull::from_mut[][src]

pub const fn from_mut<T: ?Sized>(mutt: &mut T) -> NonNull<T>
This is supported on crate feature mut_refs only.
Expand description

Const equivalent of <NonNull<T> as From<&mut T>>::from

Example

use konst::ptr::nonnull as nn;

use core::ptr::NonNull;

assert_eq!(ARR, (5, 8, 3));

const ARR: (u8, u8, u8) = unsafe {
    let mut tup = (3, 5, 8);
    swap(nn::from_mut(&mut tup.0), nn::from_mut(&mut tup.1));
    swap(nn::from_mut(&mut tup.1), nn::from_mut(&mut tup.2));
    tup
};

const unsafe fn swap(x: NonNull<u8>, y: NonNull<u8>) {
    let xm = nn::as_mut(x);
    let ym = nn::as_mut(y);
    let tmp = *xm;
    *xm = *ym;
    *ym = tmp;
}