-
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
core: Add Default::replace_default(&mut self)
#33564
Conversation
@bluss wanted something like |
I would prefer the bikeshed to be painted |
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 |
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 |
Yes, it's mostly just ergonomic, a generalization of |
Hm ok, if it's purely ergonomic then I'd definitely recommend an RFC :) |
Dang, I thought I had an easy one... :) @bluss any thoughts? Does this meet your need? |
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 |
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! |
No description provided.