struct Foo<'a> {
s: &'a str,
}
impl<'a> Foo<'a> {
fn update(&'a mut self) {
self.s = "asdf";
}
}
fn main() {
let mut foo = Foo {
s: "blah",
};
foo.update();
foo.update(); //error: cannot borrow foo as mutable more than once
}
I'm confused why adding the lifetime in the update function makes it so you can't call update twice due to foo already being mutably borrowed...After you call foo.update aren't there no mutable references to foo that exist? it seems like it should be fine to call update again