legion icon indicating copy to clipboard operation
legion copied to clipboard

Resources with a lifetime

Open tonyxty opened this issue 3 years ago • 1 comments

Currently Resources must be 'static, which makes it difficult to implement many functionalities as systems, notably rendering, since the textures / sprites / render contexts etc. usually have a lifetime associated with them.

My question is, is it possible to have resources that are generic over a lifetime parameter 'a and have Schedule::execute<'a>(&mut self, world: &mut World, resources: &'a mut Resource<'a>? After all, resources are not accessed outside of this function. Or is there some reason against this?

tonyxty avatar May 05 '21 15:05 tonyxty

I guess it has to do with rust's requirements on the Any trait. For those who encountered the same problem: std::mem::transmute can be used to circumvent this, but is "the most horribly unsafe thing you can do in Rust" according to the nomicon. Use at your own risk.

tonyxty avatar May 08 '21 13:05 tonyxty