Open
Description
In Rust's stdlib, the only way to know if the return from as_mut_ptr()
is to check the .capacity()
of the Vec.
While this is fine on its own, it does create an interesting interaction with system's APIs which expect either NULL or a valid pointer.
I think updating .as_ptr()
and .as_mut_ptr()
to return nullptr in the case of capacity() == 0
could help marginally reduce errors when using external APIs written in C or C++ where this idiom is common. There's a lot of debug checking that will specifically check for NULL but this isn't possible when the pointer's value is 0x1
, as an example.