rust-lang / book

The Rust Programming Language
https://doc.rust-lang.org/book/
Other
15.26k stars 3.44k forks source link

fix: make the reason more understandable #4074

Open spotlesscoder opened 1 month ago

spotlesscoder commented 1 month ago

That was a really good explanation - I think I finally really understood some aspect of the ownership system now. I like your idea.

Maybe we could also add this sentence from your explanation?

In idiomatic Rust, functions do not take ownership of their arguments unless they have a reason to.

because that also wasn't clear to me until you mentioned it

ghost commented 1 month ago

Not moving because I want to use the object after the function call is a dangerous thought. It leads us to think (especially for a beginner) that if I don't want to use the object after such a call, the correct approach would be to move it.

There are explicit reasons to want to move something. As chriskrycho said, reference should be the default, and move should be the exception (if there's a reason).

spotlesscoder commented 4 weeks ago

That was a really good explanation - I think I finally really understood some aspect of the ownership system now. I like your idea.

Maybe we could also add this sentence from your explanation?

In idiomatic Rust, functions do not take ownership of their arguments unless they have a reason to.

because that also wasn't clear to me until you mentioned it

@chriskrycho what's your opinion on that?

jpmelos commented 3 weeks ago

In idiomatic Rust, functions do not take ownership of their arguments unless they have a reason to.

I just want to add my voice here that adding this somewhere in the book (I don't know if exactly where this PR is, but somewhere) is very useful. I am reading this book slowly and trying to really grok every concept, and I'm in chapter 16 now, and I don't think this "implicit rule" is mentioned anywhere. I think it's a very good rule and something that should be mentioned explicitly.