How can I pass an object with a non-static lifetime to Rocket's manage
? Currently I have something along these lines:
fn foo<'a>(bar: Bar<'a>) -> Result<(), Error> {
rocket::ignite()
.manage(bar)
.mount("/", routes![index])
.launch();
Ok(())
}
But I get the following error:
cannot infer an appropriate lifetime due to conflicting requirements
note: ...so that the expression is assignable:
expected bar::Bar<'_>
found bar::Bar<'a>
note: but, the lifetime must be valid for the static lifetime...
To add more context, Bar
is a struct
containing boxed closures that get initialised using runtime args. The args contain things like passwords, keys and secrets - the actual code is open source so can be found here. It's WIP so will change and isn't entirely up-to-date, but hopefully gives an idea for the end goal.