I am writing a single thread code for learning BTree. It is in rust
Can i have multiple mutable refs of same object in a scope ?
Since this is single threaded, i don’t see why this will cause any problem ? Is there a way to tell compiler this ?
$ cargo build
54 | let l_leaf_page = self.pager.get_page(leaf_page_num as usize)?;
| ^^^^^^^^^^ mutable borrow starts in previous iteration of loop
From references chapter i see 3 conditions for which multiple borrows in same scope are not allowed :
The benefit of having this restriction is that Rust can prevent data races at compile time. A data race is similar to a race condition and happens when these three behaviors occur: Two or more pointers access the same data at the same time. At least one of the pointers is being used to write to the data. There’s no mechanism being used to synchronize access to the data.
My program is single threaded and needs no synchronization.
Please let me know how can i change my code to move forward.