-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
Changing this to a tracking issue for the feature:
- Pull request Weak::into_raw #60766
- ❓ What to do about dangling Weak (created by
Weak::new()) andT: ?Sized? These seem to be incompatible. - Stabilization
The original proposal
Hello
The Arc has the into_raw and from_raw methods. I think it would be technically possible to have the same on Weak. Obviously, as Weak is non-owning, it would be up to the caller to make sure the pointer is not dangling when used.
Would adding these (and maybe as_raw too ‒ one can get a reference out of Arc, but not from Weak) require an RFC, because the handling of these methods might be even a bit more delicate than the ones on Arc, or is this considered small enough for just a pull request & later stabilization?
Motivation
I've written the arc-swap crate that allows to keep an Arc around but make it point to some other object atomically. It uses the mentioned methods. It would make sense to have weak version of this atomic storage too.
Additionally, the as_raw would make it possible to compare if eg an Arc and Weak point to the same object (which would also come handy in some alternative of the Cache that doesn't hold the object alive needlessly).