`UniquePtr` extension
I have C++ functions that must be called with a mutable or immutable raw pointer to a C++ object I hold as a UniquePtr in a Rust struct. (The API is a bit inconsistent. More often, it needs references.) For this, I'd need as_ptr() and as_mut_ptr() on UniquePtr. UniquePtr::into_raw() goes too far by consuming the UniquePtr. into_raw() is also documented as the equivalent of std::unique_ptr<T>::release(). But there's also std::unique_ptr<T>::get(). So, the proposed two functions wouldn't be out of the ordinary.
Are you open to introduce as_ref_unchecked() and as_mut_unchecked()? They would be for cases where you're sure the pointer can never be null - undefined behavior if it is. See implementation of Option::unwrap_unchecked(); like this, there could also still be a debug_assert!().
When you search for both of the proposed function names on this std docs page, you'll see that the idea isn't new. But, building on the text there, currently CXX panics in deref() and deref_mut() in case of null pointers, unlike dereferencing raw pointers like *const T, which is undefined behavior as I understood. Maybe, it's deref...() that should be corrected to yield undefined behavior. BTW, Deref's docs page says: "this trait should never fail". Does this mean undefined behavior rather than panics?