Because calling update2
requires exclusive access to the entirety of self
: you cannot have any other borrows into it.
Operating on self.vp
directly only requires that you have no other borrows to self.vp
.
The borrow checker cannot "see" through function calls.
So reborrow part of sth doesn't freeze it as a whole? That's why line 30 works?
Please provide a link to the playground next time instead of pasting your code with lines. It is easier for us to open that link and start playing around and see exactly your code (not just a dump) and also do not need to execute arbitrary code on your machine. (Also removing those line numbers in front requires some vim voodoo )
ok:)
Oh, I got the point: c is a borrow of the .ch part and it has nothing to do with the .vp part. That's why line 30 is ok. Thank you guys.
Is this a standard practice here? I couldn't find the community guidelines to see if this was specified but was wondering as I see people using both playgrounds and inline code in posts and have done the same myself.
It's not a standard practice per se, but it's a nice way to help people get into the code fast. Otherwise, you usually have to open the playground, clear out whatever was saved from last time, paste the code in, and verify that you have a fn main
and relevant imports and such. Considerably faster to just click link to playground that someone else provided, and that doesn't ask everyone else who might be interested in helping out to duplicate that labor.
There are plenty of reasons to not do that. But some people may not even be aware that the playground exists, so it's often worth it to share a link on both ends of the conversation.
Standard practice everywhere should be: whatever makes it easiest for someone to help you. Every single barrier and speed bump is another chance for someone to lose interest or decide helping isn't worth the hassle.