-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 feature: "option_insert" #78271
Comments
As for a name, I think that either |
|
@rfcbot merge |
Team member @m-ou-se 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. |
🔔 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. The RFC will be merged soon. |
Should this be called Say, if we have a box and if we put a |
I feel that |
I'm not really against it.
Yes, that's exactly the point. The reference you get is the primary reason to call this method, not the fact that the value gets replaced − that's secondary, because if it's a replacement action that you want, then just perform an assignment. So maybe this should be reflected in the name, like with the other
I don't think Perhaps, |
We discussed this yesterday in the library team meeting, and we agreed to continue with our original decision: |
…ou-se Stabilize option_insert. FCP finished here: rust-lang#78271 (comment)
Semantics aside, I find it confusing that (Edit: Sorry for commenting on this after FCP, but since no one brought up this specific point I feel like it's still worth commenting. I'm thinking that this issue didn't get as much attention because there were a lot of FCPs (18!) in the TWiR edition where it was listed.) |
There's already |
I wonder if it would be useful to have a method on fn insert_replace(self, new: T) -> (Option<T>, &mut T) {...} 🤔 |
This seems overly complicated when you can just do: let old = option.take();
let new_ref = option.insert(new); |
This is a tracking issue for the feature "option_insert".
The feature gate for the issue is
#[unstable(feature = "option_insert")]
.This feature adds a
insert
method to anyOption
, setting its value and returning a mutable reference to this value.This method removes a cause of
unwrap
and code complexity.It allows replacing
with
Steps / History
insert
toOption
#77392insert
(As in the original PR.)insert_and_get
replace
replace_and_get
set
The text was updated successfully, but these errors were encountered: