You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really think you need an entire section on common things you might try that actually don't work because of the borrow checker, and how to fix them. The rules of the borrow checker (exactly one mutable borrow, or multiple immutable borrows) are not enough to understand it. Lots of people have the experience "Ok those are simple rules" and then they run into the problems below which the rules suggest should work and think "Wtf Rust?".
The other two issues have to do with non-lexical borrow scopes/non-lexical lifetime stuff, of which I am barely up to date on, but I know there's work being done on it currently, now that a good chunk of MIR is done.
I know Rust has been this way for a while, but I'm really optimistic that there will be progress on improving this soon, possibly before the book is printed even. I'm reluctant to document something in a permanent medium that is a known shortcoming planned to be improved upon.
While I personally love and value resources that are organized by problem/symptom and explain the solution to aid troubleshooting while coding, this book is more of an introduction to build up new Rust programmer's knowledge, read in order before, and interleaved separately with, hands-on coding. So we don't really have any sections that are "here's problem X and here's how to solve it", exactly. I think that sort of resource deserves its own website/book, since there are a lot of things along those lines that we don't have space to cover in this book!
Thank you for your feedback! I do appreciate it, but I don't think we're going to be adding a section like this to the book. ❤️
I really think you need an entire section on common things you might try that actually don't work because of the borrow checker, and how to fix them. The rules of the borrow checker (exactly one mutable borrow, or multiple immutable borrows) are not enough to understand it. Lots of people have the experience "Ok those are simple rules" and then they run into the problems below which the rules suggest should work and think "Wtf Rust?".
Here are a few examples (the first two are pretty long-standing):
Method calls borrow self at the same time as the parameters.
You can't do
foo.set(foo.get() + 1)
.The fix is to add an extra temporary variable.
Lexical borrows
The solution is to add extra scopes.
The map issue
There are a whole lot of issues people have about doing stuff with maps in match statements and the Entry API. E.g. you can't do something like this:
I would suggest searching Stackoverflow for 'rust', 'borrow-checker' questions to find the most common questions and solutions.
The text was updated successfully, but these errors were encountered: