Follow-up of Why doesn't Weak::new() work when Rc::downgrade() does?
When attempting to implement Weak::new()
in a way that would NOT require i
Yes, there is a way, and it was actually submitted to the standard library:
This change makes it so that Weak::new() allocates no memory at all. Instead, it is created with a null pointer. The only things done with a Weak are trying to upgrade, cloning, and dropping, meaning there are very few places that the code actually needs to check if the pointer is null.