-
Notifications
You must be signed in to change notification settings - Fork 358
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
Talk about mem::take instead of mem::replace #200
Conversation
#96 can be closed with this |
Co-authored-by: simonsan <14062932+simonsan@users.noreply.github.com>
Sorry, ignore the ping to re-review. I though that was approved before my changes. |
No problem. ;-) |
Should we rename the file to mem-take.md? |
Talked about it here, still neded to be discussed though |
Regarding
I find (note that empty strings don't allocate) part a bit misleading. As if, if empty string allocated then we couldn't write like this. Wouldn't the allocated mem be dropped even if it allocated? Just after |
From the docs.
Empty String does not allocate. I don't understand why is that a nonsense. |
@pickfire
I mean writing |
The motive behind this PR is that mem::take is often neater and more elegant than mem::replace, especially in the example listed in the original mem::replace article.
This PR changes the mem::replace article to instead focus on mem::take. The article does mention mem::replace as an alternative if you don't want the default value to be the
src
, or if your type doesn't implementDefault
.This also fixes a typo in the source code block that prevented the block from being compiled and executed, and then fixes a compile error in the block itself.
EDIT of Maintainer: Closes #96