-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add std::mem::take as suggested in #61129 #61130
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
naming nit: |
@cramertj I sort of intentionally wanted it to be relatively short and concise. I see the point about wanting the name to indicate what gets left in its place though. The signature would likely tell you very quickly, but we may want it reflected in the name as well. Maybe |
|
For prior art: naming as |
@rfcbot fcp merge |
Team member @sfackler 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. |
I’d prefer this be named This is closer to a
|
I personally prefer |
Is there any precedence for functions in the standard library that are related to |
Yes -- #61130 (comment) mentions |
Ah, I saw that, but wasn't aware of how it works. I have no objections then. |
Make sure to update the pr/issue to reflect the |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
In |
☔ The latest upstream changes (presumably #61317) made this pull request unmergeable. Please resolve the merge conflicts. |
The name `swap_default` was suggested but rejected. @SimonSapin observed that this operation isn't really a `swap` in the same sense as `mem::swap`; it is a `replace`. Since `replace_default` is a bit misleading, the "correct" name would be `replace_with_default`, which is quite verbose. @czipperz observed that we have precedence for using `take` to refer to methods that replace with `Default` in `Cell::take` and `Option::take`, so this reverts commit 99c00591c29b472c8a87c4a9342d0e0c508647a3 to return to the original `take` method name. The name `replace_with_default` was suggested, but was deemed too verbose, especially given that we use `take` for methods that replace with `Default` elsewhere.
Given that it's a function, I like the |
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. |
@bors r+ |
📌 Commit 5a01b54 has been approved by |
⌛ Testing commit 5a01b54 with merge f5e8c96c1dd9a6d9d71b328846264570b9233bff... |
Add std::mem::take as suggested in rust-lang#61129 This PR implements rust-lang#61129 by adding `std::mem::take`. The added function is equivalent to: ```rust std::mem::replace(dest, Default::default()) ``` This particular pattern is fairly common, especially when implementing `Future::poll`, where you often need to yield an owned value in `Async::Ready`. This change allows you to write ```rust return Async::Ready(std::mem::take(self.result)); ``` instead of ```rust return Async::Ready(std::mem::replace(self.result, Vec::new())); ``` EDIT: Changed name from `take` to `swap_default`. EDIT: Changed name back to `take`.
@bors retry r0lled up |
Add std::mem::take as suggested in #61129 This PR implements #61129 by adding `std::mem::take`. The added function is equivalent to: ```rust std::mem::replace(dest, Default::default()) ``` This particular pattern is fairly common, especially when implementing `Future::poll`, where you often need to yield an owned value in `Async::Ready`. This change allows you to write ```rust return Async::Ready(std::mem::take(self.result)); ``` instead of ```rust return Async::Ready(std::mem::replace(self.result, Vec::new())); ``` EDIT: Changed name from `take` to `swap_default`. EDIT: Changed name back to `take`.
☀️ Test successful - checks-travis, status-appveyor |
This PR implements #61129 by adding
std::mem::take
.The added function is equivalent to:
This particular pattern is fairly common, especially when implementing
Future::poll
, where you often need to yield an owned value inAsync::Ready
. This change allows you to writeinstead of
EDIT: Changed name from
take
toswap_default
.EDIT: Changed name back to
take
.