NonZero
type RS-E1026Transmutes from integers to NonZero
* types can be unsound.
Transmutes work on any type provided and might cause unsoundness
when those types change elsewhere. The new_unchecked
method
only works for the appropriate types instead, restricting the transmutes
to compatible integer conversions.
Consider using the new_unchecked
method instead.
fn foo() {
let _non_zero: NonZeroU32 = unsafe { std::mem::transmute(123) };
}
fn foo() {
let _non_zero = unsafe { NonZeroU32::new_unchecked(123) };
}