Document that `World::run_system_cached(_with)` needs type hints for error handling
- Dominant language
- Rust
- Stars
- 48.2k
- Forks
- 4.8k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 171
Description
## How can Bevy's documentation be improved?
```rust
fn system() -> Result {
Ok(())
}
fn exclusive_system(world: &mut World) -> Result {
// does not work
world.run_system_cached(system)?;
// does work
() = world.run_system_cached(system)?;
// also works, but lol
run_system_cached_with::<_, (), _, _>(system)?;
Ok(())
}
```
From @chescock on [Discord]():
> Yeah, that one the one sharp edge I couldn't figure out how to file down. It works for systems that return `()`, and it works for `commands.run_system_cached` since that fixes the output type to `()`, it usually works for `world.run_system` since you give an explicit type to the `SystemId`.
If we can't fix it, let's at least document it :)
The specific error is
```
error[E0277]: the trait bound `std::result::Result<(), bevy::prelude::BevyError>: IntoResult` is not satisfied
--> src/demo/ai/hearing/process.rs:55:29
|
55 | world.run_system_cached(system)?;
| ----------------- ^^^^^^ the trait `IntoResult` is not implemented for `std::result::Result<(), bevy::prelude::BevyError>`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `IntoResult`:
std::result::Result
std::result::Result
= note: required for `fn() -> std::result::Result<(), bevy::prelude::BevyError> {system}` to implement `bevy::prelude::IntoSystem<(), !, (IsFunctionSystem, fn() -> std::result::Result<(), bevy::prelude::BevyError>)>`
note: required by a bound in `system::system_registry::::run_system_cached`
--> /home/hhh/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/bevy_ecs-0.17.2/src/system/system_registry.rs:505:48
|
505 | pub fn run_system_cached + 'static>(
| ^^^^^^^^^^^^^^^^^^^^ required by this bound in `system::system_registry::::run_system_cached`
```
Contributor guide
Research direction
Start with the documented World::run_system_cached and run_system_cached_with APIs and the compiler diagnostic pointing to system_registry.rs:505. Document why a type hint is needed for Result-returning systems, including the working forms shown in the issue. Done means the API documentation explains the error and provides a clear workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100