Is there any particular reason why the type signature of Rc::downgrade
doesn't use &self
and instead this: &Self
as parameter?
To avoid Naming pollution when deref
ing? But why does Weak
then use Weak::upgrade(&self)
instead of Weak::upgrade(this: &Self)
To avoid Naming pollution when
deref
ing?
Exactly. Lots of built-in containers like Rc
and Box
try very hard to minimize the number of inherent functions defined on them, favoring associated functions instead to allow the structure to be as transparent as possible.
Weak
, on the other hand, does not implement Deref
. You must consciously try to get the value from it, using upgrade
, and that function can fail (a Deref
impl should never fail) if the value pointed to has already been dropped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With