Mutable borrow in a getter not living long enough
问题 pub type Data = i32; pub struct Foo { data: Data, } impl Foo { pub fn data_mut(&mut self) -> &mut Data { &mut self.data } } pub struct Context { data: Data, foos: Vec<Foo>, } impl Context { pub fn broken(&mut self) -> &mut Data { // What are the lifetimes here that make this version not work? &mut self.foos.first_mut().unwrap().data_mut() } pub fn working(&mut self) -> &mut Data { &mut self.foos.first_mut().unwrap().data } } fn main() {} (Playground) error[E0597]: borrowed value does not live