Skip to content
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

Mention about mem::replace, Option::replace and Option::take #4163

Closed
radumarias opened this issue Dec 16, 2024 · 4 comments
Closed

Mention about mem::replace, Option::replace and Option::take #4163

radumarias opened this issue Dec 16, 2024 · 4 comments

Comments

@radumarias
Copy link

  • I have searched open and closed issues and pull requests for duplicates, using these search terms:

    • mem::replace
    • replace
    • Option::replace
    • Option::take
  • I have checked the latest main branch to see if this has already been fixed, in this file:

URL to the section(s) of the book with this problem:

Description of the problem:

No mention about mem::replace, Option::replace and Option::take.
Also about swap.

Suggested fix:

Would have been great to mention about mem::replace and Option::replace and Option::take as they are very used later on, especially in https://rust-unofficial.github.io/too-many-lists/ and they are very useful.

@chriskrycho
Copy link
Contributor

Thanks for the suggestion. Option::take does appear in the book, including in both Ch. 17 (starting here) and ch. 20 (starting here).1 I’m afraid we aren’t going to look for specific places to mention mem::replace or Option::replace, though. The approach the book takes is not to mention everything that would be useful—it’s already way too big!—but to cover the specific APIs which help us introduce the language.

These are the APIs which caught your attention, and quite rightly: they’re important and useful! There are equally important APIs that would catch someone else’s attention, though, and so on ad infinitum.

As noted over on #4104, we have a more general challenge here of figuring out where to document key parts of the language, still less how to help people learn what APIs exist—but this book, for good and for ill, just cannot cover everything!

Footnotes

  1. Note for posterity: starting with Rust 1.85, these will be chs. 18 and 21 respectively, due to the addition of a new Chapter 17 covering async and await. You can see the updated link locations on nightly now:

    Note that these links are currently dead, though: they don’t go anywhere in Rust 1.83 or 1.84!

@chriskrycho chriskrycho closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
@radumarias
Copy link
Author

Btw, it's a great book, I've enjoyed it a lot, read it all and will read it again.

Agree, sorry for Option::take, was mostly about Option::replace.

https://rust-unofficial.github.io/too-many-lists/second-option.html?highlight=mem%3A%3Areplace#using-option

First, mem::replace(&mut option, None) is such an incredibly common idiom that Option actually just went ahead and made it a method: take.

Given that this is a very common idiom, I think it would help to include it in the book, but only if you feel better.

I'm also trying to write a book https://docs.google.com/document/d/1sInnf4umYPBi_zSmKKF4k4w8TJ7jVldUwoV9bOsERM4/edit?usp=sharing would help me to give me some feedback :)

@chriskrycho
Copy link
Contributor

As I said, there are many very common idioms we do not discuss in the book. We just cannot—there is not enough room to cover everything while still working as an introduction to the language. Happily, there are great resources like the one you linked there which cover many of the things we cannot cover for length reasons!

Good luck on your own book effort!

@radumarias
Copy link
Author

Good luck on your own book effort!

Thank you, I would appreciate it if you could give me some feedback and advice, as you clearly have experience in writing a book. You can send it to radumarias@gmail.com. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants