You are trapped in life. Adding the same lifetime to more links will more limit your program. Adding more lives and providing each link with the shortest possible lifetime will allow more programs. As @ o11c notes, eliminating life time limits 'a will solve your problem.
impl<'a> Context<'a> { fn get_function(&mut self, fun_name: &str) -> Result<Function<'a>, Error> { self.program.get(fun_name).map(|f| *f).ok_or(Error::FunctionNotFound) } fn call(&mut self, fun_name: &str) -> Result<(), Error> { let fun = try!(self.get_function(fun_name)); self.call_stack.push(fun); Ok(()) } }
The reason for this is that rust inserts new lifetimes, so in the compiler the signatures of your functions will look like this:
fn get_function<'b>(&'b mut self, fun_name: &'b str) -> Result<Function<'a>, Error> fn call<'b>(&'b mut self, fun_name: &'b str) -> Result<(), Error>
Always try not to use the lifetime and let the compiler be smart. If this fails, donβt spray your life time everywhere, think about where you want to transfer ownership and where you want to limit the lifetime of the link.
source share