You cannot borrow self mutably more than once at the same time because Rust's borrow checker prevents simultaneous mutable access to ensure memory safety. Separate the mutable borrows into distinct scopes so the first borrow ends before the second one begins.
impl Rectangle {
fn process(&mut self) {
{
// First mutable borrow scope
self.width += 1;
}
// First borrow ends here
// Second mutable borrow scope
self.height += 1;
}
}
Alternatively, if you need to use the same value multiple times, borrow it immutably first, then mutate it later, or use split_at_mut for slices.