https://doc.rust-lang.org/std/boxed/struct.Box.html#method.into_raw
The pointer will be properly aligned and non-null.
Sometimes we take its return value for use in a NonNull
. But NonNull::new
returns an Option
which needs an extra unwrap
. I'm against unwrap
in general, and in this example, it's like we are converting NonNull
to * mut
to NonNull
itself. Is there any consideration against returning NonNull
for functions like Box::into_raw
that we know return a non-null pointer?
The only thing I can think of is NonNull
is covariant while * mut
is invariant. This raises a related question whether NonNull
is losing orthogonality by combining non-null and covariance in one data structure. Is there a need for something like RawNonNull
which only exhibits non-null and nothing else?