Hi Guys,
in a block, I'm calling a function returning a mutable reference. My understanding was that the reference is only valid within the block (thus is "disposed" as after the block closes).
However, when I'm trying to borrow again after the block closes, rust complaints with our beloved cannot borrow
*self as mutable more than once at a time
. This seems to be related to returning the value (when commenting out the return
line, rust happily accepts this).
Can someone please shed some light into what is happening here?
Thanks!
struct Test {
item: String
}
impl Test {
fn foo<'a>(&'a mut self) -> &'a str {
{
let x = self.bar();
if x.is_ascii() {
return x
}
}
self.bar() // error
}
fn bar<'a>(&'a mut self) -> &'a str {
&self.item
}
}