Allow readonly queries and system parameters to be initialized with only `&World`.
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 161
Description
# Objective
Because of queued component registration (#18173), it is now plausible to initialize some kinds of queries and system parameters without needing `&World`. We should take advantage of that to effectively replace the `try_query` API.
# Design
We currently have
```rust
triat WorldQuery {
fn init_state(world: &mut World) -> Self::State;
}
```
and
```rust
triat SystemParam {
fn init_state(world: &mut World, system_meta: &mut SystemMeta) -> Self::State;
}
```
What we need is to add methods:
```rust
triat WorldQuery {
fn init_state_readonly(world: &World) -> Self::State;
}
```
and
```rust
triat SystemParam {
fn init_state_readonly(world: &World, system_meta: &mut SystemMeta) -> Self::State;
}
```
But these methods shouldn't live on these traits directly since not all `SystemParam`s and `WorldQuery`s will be able to implement them.
There's a few options here:
1. Put these methods on existing `ReadOnlySystemParam` and `ReadOnlyQueryData`. But there *may* be items that are readonly, but require mutation to initialize.
2. Put these methods on brand new traits, adding complexity but keeping flexibility.
3. Do option 1, but include a const bool flag to determine if `init_state_readonly` is valid to be called. This is a middle ground for complexity, but introduces a correctness danger.
Contributor guide
Assessment
This issue has not been assessed yet.