I am using the spec crate to implement some framework. When I want to reduce some LazyUpdate boilerplate code like this
pub fn lazy_exec<'a, T, D>(f: T)
where
D: SystemData<'a>,
T: Send + Sync + FnOnce(D) + 'static,
{
let lazy_update = unsafe { ECS_CONTEXT.assume_init_ref().lazy_update.as_ref().unwrap() };
lazy_update.exec_mut(move |world| {
world.exec(f);
})
}
But the compiler complains about E0521 like this
error[E0521]: borrowed data escapes outside of closure
--> src\lib.rs:273:9
|
266 | pub fn lazy_exec<'a, T, D>(f: T)
| -- lifetime `'a` defined here
...
272 | lazy_update.exec_mut(move |world| {
| -----
| |
| `world` is a reference that is only valid in the closure body
| has type `&'1 mut specs::World`
273 |
world.exec(f);
| ^^^^^^^^^^^^^
| |
| `world` escapes the closure body here
| argument requires that `'1` must outlive `'a`
I can't figure out how to resolve this. Thanks for your help in advance.