pub const unsafe fn as_mut<'a, T: ?Sized>(ptr: NonNull<T>) -> &'a mut T
Available on crate feature
mut_refs
only.Expand description
Const equivalent of NonNull::as_mut
.
§Safety
This has the same safety requirements as NonNull::as_mut
§Example
use konst::ptr::nonnull;
use core::ptr::NonNull;
assert_eq!(TUP, (13, 15, 18));
const TUP: (u8, u8, u8) = unsafe {
let mut tuple = (3, 5, 8);
mutate(nonnull::from_mut(&mut tuple.0));
mutate(nonnull::from_mut(&mut tuple.1));
mutate(nonnull::from_mut(&mut tuple.2));
tuple
};
const unsafe fn mutate(x: NonNull<u8>) {
*nonnull::as_mut(x) += 10;
}