-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Tracking Issue for arc_unwrap_or_clone
#93610
Comments
Apologies if this is the wrong place for this comment, feel free to delete. Is there a technical reason why If I have |
@patrick96 it's because Apologies if I'm using the wrong terminology but that's the gist of it. |
That makes sense. Thanks for the explanation :) |
(Couldn't comment on the thread in IRLO as it has been closed.) |
There is precedence for this pattern: `Option::unwrap_or` for example.
…On Tue, 13 Sept 2022, 01:03 Tobias Bucher, ***@***.***> wrote:
unwrap_or_clone sounds like a bad name to me: unwrap has a connotation of
potentially panicking code in Rust. The other suggested names in #91589
<#91589> all sound better to me.
(Couldn't comment on the thread in IRLO as it has been closed.)
—
Reply to this email directly, view it on GitHub
<#93610 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAKT4XWYWI7GWMGR4SYTBZDV57AFJANCNFSM5NOMB77Q>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
True, I overlooked it. |
I think this name is good, and it's easy for me to understand what it means. I'm really looking forward for this to be fcped and stabilized. |
At $work we've been using the exact same implementation as the one used in nightly (https://doc.rust-lang.org/src/alloc/sync.rs.html#1535), it works perfectly well |
While I like the proposal very much (for it's convenience), I feel like I want to point out something that might be interesting as well in the future and is related: It's not possible to use Consider wanting to remove an element from an I understand that there would need to be something like a |
Try this: let a: Rc<Vec<_>> = ...;
Rc::make_mut(&mut a).pop(); // make_mut is stable The code above will copy vector if needed. (I didn't test the code) |
Yes, good point, thanks for bringing it up. However a Vec is unfortunately another layer of indirection. Typically I have something like |
Is there something that still needs to be done before this can go to FCP? I just came across the need for this and noticed that the comments seem positive with confirmation that it works at $work for at least one commenter above, so am wondering what if anything is preventing it moving forward? |
Pinging @rust-lang/t-libs here for input. There seems to be consensus on stabilizing this. Can anyone start an FCP? I'd be happy to work on a stabilization PR (with some guidance) |
@rust-lang/libs-api:
Both of these are already expressible on stable using the following incantation, which is exactly the standard library's implementation too: The rationale for a dedicated method is that "I need a |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
@davidhalter and others: #116113 is related |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
I believe that can check off the stabilization? |
And update the documentation as this seems to have been stabilized. |
I am getting this: warning: the feature `arc_unwrap_or_clone` has been stable since 1.77.0-nightly and no longer requires an attribute to enable |
Arc<str> stores the string inline on the heap together with the strong_count and weak_count of the Arc. This means it has a different in-memory representation than Box<str> and thus can't be converted into a Box<str> without copying the contents. A Box<str> to Arc<\str> conversion also copies the string contents into the Arc allocation. |
@Bwallker I understand that. But moving elements from an Rc to a Vec is different from cloning. The opposite direction is already possible. This means that you can write I understand that moving is different from |
GitHub deleted all my angle brackets. I was specifically talking about converting between string types because there's no difference between moving and cloning characters. |
Feature gate:
#![feature(arc_unwrap_or_clone)]
This is a tracking issue for
arc_unwrap_or_clone
. This feature adds methods toRc
/Arc
to gain access to the contained value, by unwrapping if there is exactly one reference, or cloning otherwise. It is equivalent to cloning the inner value, but saves the clone operation if the caller has the only reference to the rc'd value.Public API
Steps / History
Arc::unwrap_or_clone
#91589Unresolved Questions
More bikeshedding on the name is possible. Existing discussion on irlo.There seems to be consensus that the current name is good.The text was updated successfully, but these errors were encountered: