A single-threaded process will call one of my
extern "C" Rust functions and pass it a raw pointer to a structure with nested raw pointers. Here's what I mean.
Null-checking the nested pointers is tedious and error-prone. I could forget to null-check a pointer.
The nullable pointer optimization says the memory layout of a
*const T is bitwise-equivalent to a
If I replace the raw pointers with
Option references, then I can null-check by using the
? operator to short-circuit a function that returns an
Option. Furthermore, it's impossible for me to accidentally dereference one of the nested pointers without null-checking. Here's what I mean.
I've tested both the raw pointer and the
Option reference solutions, and they both produce the same results.
I would like to know whether this conversion is unsound and why.