Convert ref-to-raw-pointer to ref-to-NonNull without transmute?
The Rust Programming Language Forum
Convert ref-to-raw-pointer to ref-to-NonNull without transmute?
Consider this toy function: fn ptr_as_nonnull<T: ?Sized>(input: &*mut T) -> Option<&NonNull<T>> { if input.is_null() { None } else { // Is it possible to implement this without transmute? Some(unsafe { std::mem::transmute(input) }) } } Is that function sound? I know that NonNull is repr(transparent), but that function is transmuting a raw pointer ref as a NonNull ref, not a raw pointer value as a NonNull value. Is it possible to implement that function wit...
0 comments
No comments yet.