-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Arc::try_unique #23844
Added Arc::try_unique #23844
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
Thanks for the PR! In the past we've generally been pretty hesitant about adding inherent methods on smart pointers, however as they will shadow all other methods of the same name. In the past we've requested that extra functionality for smart pointers go as top-level functions as well. Also, we do seem to definitely have a bit of a sprawling story for extra functionality on smart pointers, there's an interesting subset of functionality between cc @aturon, do you have thoughts on adding apis such as this? |
@alexcrichton thanks for the info! May I wonder why top-level functions are preferred for smart pointers instead of the member functions? I'd be happy to use the existing functions without introducing more, but as I said there is no way to get the mutable contents at the moment without As for the intersection, for gfx-rs we'll need some sort of abstraction over |
Right now if a smart pointer let ptr: P<T> = ...;
ptr.foo(); This is because the receiver's methods trump the |
Oh, thanks, I get this now! |
You can indeed! I also forgot, but you can also do |
Just to clarify - are we waiting for me to change the methods to be global, or are we blocked by @aturon to look into it? |
@kvark Sorry for the delay. I'm happy to add a top-level experimental APIs like this. I'd like to suggest a single method |
@aturon Right, I only added I'll update the PR shortly. Thanks for having a look! |
Done. Anything else I need to fix? |
While trying to implement parallel ECS processing, I stumbled upon the need to mutate `Arc` contents. The only existed method that allowed that was `make_unique`, but it has issues: - it may clone the data as if nothing happened, where the program may just need to crash - it forces `Clone` bound, which I don't have The new `try_unique` allows accessing the contents mutably without `Clone` bound and error out if the pointer is not unique.
⌛ Testing commit 39aa668 with merge 6a7d49e... |
💔 Test failed - auto-mac-32-opt |
@alexcrichton but.. bors showed that my docs were incorrect. Are you sure about merging? |
No worries! I fixed them in the rollup |
@alexcrichton thanks! My machine takes ages to build and check everything... |
Is there some reason this was named |
@kballard no, I wasn't aware of |
There's a lot of precedent in the collection types (including slices) for a |
@kballard I'll make a PR tonight to change it. |
Awesome, thanks. That's one less thing for me to try and remember (since I'm on vacation right now 😀) |
While trying to implement parallel ECS processing, I stumbled upon the need to mutate
Arc
contents. The only existed method that allowed that wasmake_unique
, but it has issues:Clone
bound, which I don't haveThe new
try_unique
allows accessing the contents mutably withoutClone
bound and error out if the pointer is not unique.