Open Zeenobit opened 1 year ago
I have a somewhat related RFC: https://github.com/bevyengine/rfcs/pull/68.
This would make derived WorldQuery
types use a lifetime parameter, which I think is far cleaner than using 'static
lifetimes for everything, and results in fewer generated types.
How can Bevy's documentation be improved?
https://docs.rs/bevy/latest/bevy/ecs/query/trait.WorldQuery.html
When using
#[derive(WorldQuery)]
, based on the documentation, we should be using'static
lifetime for all references:However, it seems like you can also use a lifetime parameter:
In fact, I've been using this lifetime parameter in my code (without knowing it should be
'static
) to allow construction ofWorldQuery
types from&World
. For example:I find this pattern useful because it allows these query types be used in systems, as well as any code that has exclusive
&World
access (such as debug, tests, editor, etc.):Is this usage an anti-pattern?
'static
despite having the option for them to not be so. Better yet, I'd say the derive macro should check for lifetimes and disallow them if we have to use'static
.'static
, and this is an acceptable usage, then I propose it should also be documented as such. The statement about references having to be static should be replaced with documentation on the lifetime parameter and how to use it correctly.