Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upcore: Add `Default::replace_default(&mut self)` #33564
Conversation
This comment has been minimized.
This comment has been minimized.
|
@bluss wanted something like |
This comment has been minimized.
This comment has been minimized.
samlh
commented
May 11, 2016
|
I would prefer the bikeshed to be painted |
This comment has been minimized.
This comment has been minimized.
|
Hmm, For an analogy, this is a bit like C++ move semantics, where the value is transferred but the origin is still left in a usable (unspecified) state. Here we're specifying the source will be |
alexcrichton
added
the
T-libs
label
May 11, 2016
alexcrichton
self-assigned this
May 11, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks for the PR! This is a stable prelude trait so despite this method being unstable it's borderline "requires an RFC" territory. (I could kinda go either way, cc @rust-lang/libs) Also, could you elaborate on some of the rationale for this as well? Can this lead to optimizations in some cases or is it just a more ergonomic |
This comment has been minimized.
This comment has been minimized.
|
Yes, it's mostly just ergonomic, a generalization of |
This comment has been minimized.
This comment has been minimized.
|
Hm ok, if it's purely ergonomic then I'd definitely recommend an RFC :) |
This comment has been minimized.
This comment has been minimized.
|
Dang, I thought I had an easy one... :) @bluss any thoughts? Does this meet your need? |
This comment has been minimized.
This comment has been minimized.
|
Thanks for writing the PR. I don't think it is an easy one. I don't prefer changing Default, but I can see that it has some advantages.^ The original suggestion was to add a method The inspiration for that is threefold, the similarity with Option::take, the regular need for this call, and thirdly to make it easy to read and explain the code. It's one of those inspirations that come from discussing solutions to simple situations with newcomers to rust. It does functionally meet the need (but the functionality was already present with replace), it is ergonomic, so that's a great plus, but with this name I don't think it is as nice as I think this is an area where we should say to be correct: it can be implemented similarly in an external crate, and we should use experience from that before including. ^ Default advantage: baseline feature generally available |
This comment has been minimized.
This comment has been minimized.
|
OK, thanks for all the feedback! To be honest, I was only mildly interested in this, enough to try for the low-hanging fruit. If someone else would like to go further with an RFC and/or external crate, please feel free! |
cuviper commentedMay 11, 2016
No description provided.