Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Rust compiler forcing "needlessly" verbose code?
I have somethis that I find weird (maybe it is just me). The rust compiler does not like it when I do this:
self.cars[Cx].SetTmpStatus(self.cars[Cx].LoadedP());
I get error[E0502]: cannot borrow
self.cars as immutable because it is also borrowed as mutable
The "cure" seems to be:
{
let temp = self.cars[Cx].LoadedP();
self.cars[Cx].SetTmpStatus(temp);
}
Where:
pub fn LoadedP(&self) -> bool {self.loadedP}
pub fn SetTmpStatus(&mut self, p: bool) {self.tmpStatus = p;}
Is this really necessary? Or is an "unintented consequence" of the borrow checker?
2 posts - 2 participants
🏷️ Rust_feed