Followup question... the following fails with
cannot borrow `*self` as mutable because it is also borrowed as immutable
struct Foo<'a> (&'a str);
impl<'a> Foo<'a> {
fn init(self: &'a mut Self) {
let value = self.get_value();
self.do_something(value);
}
fn get_value(self: &'a Self) -> &'a str {
self.0
}
fn do_something(self:&'a mut Self, _: &'a str) {
}
}
fn main() {
let mut foo = Foo ("hello world!");
foo.init();
}
And if I change get_value
to accept self: &'a mut Self
then I get:
error[E0499]: cannot borrow `*self` as mutable more than once at a time
Ideas? Gotta run - but will be back later and excited to see some thoughts on this