Hello! This is my first time using Rust, could someone please help me understand why this code is giving me the error: "cannot borrow *self as mutable more than once at a time second mutable borrow occurs here"
fn scan_string(&mut self) {
if let Some(mut next_char) = self.source.peek() // first mutable borrow {
while *next_char != '"' { // first borrow later used here
if *next_char == '\n' {
self.process_newline(); // error message is given here
}
self.advance(); // and here
match self.source.peek() { // and here
Some(c) => next_char = c,
None => (), // todo error
}
}
}
}
But something similar like this does not
fn skip_whitespace(&mut self, initial_char: char) {
if initial_char == '\n' {
self.process_newline();
}
if let Some(mut next_char) = self.source.peek() {
while next_char.is_whitespace() {
if *next_char == '\n' {
self.process_newline();
}
self.advance();
match self.source.peek() {
Some(c) => next_char = c,
None => return,
}
}
}
}
For reference, every method on self here is mutable. Thanks in advance! 🙂