Hi, the borrow checker complains about the following (simplified) code:
fn get_true<'a>(vec: &'a mut Vec<bool>, index: usize)-> &'a bool{
let my_bool: &bool = vec.get(index).unwrap();
if *my_bool{
return my_bool;
}
vec[index] = true;
return vec.get(index).unwrap();
}
Essentially I want to return a reference to an element of a vec. If a condition is met I want to return it immediately, otherwise I want to modify the vec and return something else. This seems like it should it should be able to stop borrowing after checking my condition but instead I get cannot borrow `*vec` as mutable because it is also borrowed as immutable and returning this value requires that `*vec` is borrowed for `'a`