I'd like to do something like the following, but the compiler keeps complaining about the lifetimes, as if the World is kept in the Container after the function completes. Does anyone know how you could do it? Might be a generic rust question, but I've tried to replicate it without bevy and that seemed to work fine.
use bevy::prelude::*;
fn main() {
App::new()
.insert_resource(Container::default())
.add_systems(Update, exclusive)
.run();
}
fn exclusive(world: &mut World) {
let mut container = world.remove_resource::<Container>().unwrap();
container.world = Some(world);
let world = container.world.take().unwrap();
world.insert_resource(container);
}
#[derive(Resource, Default)]
struct Container<'w> {
world: Option<&'w mut World>,
}