Is there a guide that covers
I can’t find them in the book.
ref and ref mut are part of patterns
Thanks for raising this, maybe that’s a common confusion. /cc @steveklabnik
They are very confusing. Especially since they come up when I’m trying to borrow fields from nested structs.
But it was in the context of a match, was it? So “patterns” is the right place to put it, but maybe a hint in the references section, that the information can be found otherwise would be helpful.
My intuition when dealing with borrow shenanigans is to refer to the borrowing section of the book. I didn’t think of pattern matching.
I would love to see examples of mutably borrowing from nested structs in the guide (maybe
I have a hard time understanding what your specific problem was. Can you post a minimal example of what was failing?
I don’t have a code example right now.
My main issue with
ref mut when applied to nested data is that I don’t understand how they interact with the lifetime, ownership, and mutability of the parent data.
I’ll post a better example when I get home.
While trying to come up with a code example demonstrating my confusion on how
ref mut work I think I got it. So, problem solved ???
The way I understand it is that
ref mut are needed because in a
"&" deconstructs references, so we need a way to construct references to captured variables. Did I get this right?