rust-objc
rust-objc copied to clipboard
Implement Default for WeakPtr?
In the code I'm writing, it would be useful to have Default
on WeakPtr
so I don't need to wrap it in an extra layer of Option
. This would make it more like std::rc::Weak and I think presents no problem because the null pointer is valid.
Happy to send a PR, I'm filing as an issue first to verify that it would be wanted, and in case there's a problem with the idea I'm missing.
alloc::rc::Weak
is actually core::ptr::NonNull
internally - they use dangling pointers to create a Default
implementation.
But yeah, WeakPtr
could probably have a Default
impl of WeakPtr::new(core::ptr::null_mut())
, but I don't think we want this, since load
would now return null
in two cases: If the object was deallocated or if it was created from a null pointer - that is, you can't distinguish these two cases, which makes for a bad API IMO.