I have taken off all extra irrelevant code to come to this clean one to reproduce the error I am getting:
trait EventsHandler{}
struct Engine{}
struct Request{}
struct RequestHandler<'a> {
r: &'a mut Request
}
impl<'a> EventsHandler for RequestHandler<'a>{}
impl Engine {
pub fn exec(&mut self, script: &str, handler: Box<dyn EventsHandler>){ }
}
pub fn handle_request(script: &str, r: &mut Request) {
let r_h:RequestHandler =RequestHandler {r};
let handler = Box::new(r_h);
let mut engine = Engine{};
engine.exec(script, handler);
}
and the error is:
error: explicit lifetime required in the type of `r`
label: lifetime `'static` required
The error is pointing to the parameter 'handler' in the last line of code.
As far as I can see everything seems live long enough. I can't see why there is a need for static and how I can go and fix that need or rewrite the code to avoid that requirement.