“error: closure may outlive the current function” but it will not outlive it
When I try to compile the following code: fn main() { (...) let mut should_end = false; let mut input = Input::new(ctx); input.add_handler(Box::new(|evt| { match evt { &Event::Quit{..} => { should_end = true; } _ => {} } })); while !should_end { input.handle(); } } pub struct Input { handlers: Vec<Box<FnMut(i32)>>, } impl Input { pub fn new() -> Self { Input {handlers: Vec::new()} } pub fn handle(&mut self) { for a in vec![21,0,3,12,1] { for handler in &mut self.handlers { handler(a); } } } pub fn add_handler(&mut self, handler: Box<FnMut(i32)>) { self.handlers.push(handler); } } I get this