-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Improve Drop description (src/ch15-03-drop.md) #4181
Comments
That is an interesting idea, thank you very much for reporting. My personal view is more, that describing too much details in the first book that people read about Rust makes not that much sense. I read the official Rust book in October 2023, and had the feeling that some stuff was explained already in too much detail. Rust is a complex language -- if we explain all topics in much detail, it would people take very long to learn the language. Of course we have to explain what is really needed. For the Drop trait, it is more my feeling, that understanding the principle working is important. But I would assume that most beginners will not construct data structures where they really have to implement Drop. And when they have to do so, there is now AI available: Just ask, and in seconds you get typically a very good explanation with working code examples. And we can always ask for more details if we want. For an advanced book, your proposal might be a good idea indeed. |
Hi @StefanSalewski Do you think this description would fit better in Rust by Example? |
Yes, I think "Rust by example" might be a good place for your example. But there might be many other possible locations. Note that I am just a plain Rust user, so I have absolutely no influence, and maybe my feeling is just wrong. At least I can tell that I will not include such an example in my own "Rust for C-Programmers" book, as that book should remain as compact as possible, and it has already more pages than initial planed. When you add your example somewhere, it would be good to mention related crates like https://docs.rs/tempfile/latest/tempfile/ |
Hello guys!
TLDR: my main idea is to provide something more obvious than just
println!("Dropping CustomSmartPointer with data
{}!", self.data);
. For instance, when we are talking about files, the current book chapter states that "...lets you customize what happens when a value is about to go out of scope.", but it doesn't really show any customization behavior. So I thought it might be helpful for newcomers to see that drop() could be useful when working with fixtures, so you don't need to write a functionfn clear_data()
and call it manually after every test - you can just extend drop behavior.I thought about something like this + description:
What do you think? The example of course could be improved or changed, but what about the principal idea?
PS: I don't think this description belongs in the standard library docs (https://github.com/rust-lang/rust/blob/master/library/core/src/mem/mod.rs#L940) since this behavior is obvious, but I think it could be useful for The Rust Book.
The text was updated successfully, but these errors were encountered: