Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resources with a lifetime #259

Open
tonyxty opened this issue May 5, 2021 · 1 comment
Open

Resources with a lifetime #259

tonyxty opened this issue May 5, 2021 · 1 comment

Comments

@tonyxty
Copy link

tonyxty commented May 5, 2021

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
Copy link
Author

tonyxty commented May 8, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant