-
-
Couldn't load subscription status.
- Fork 4.2k
Description
Bevy version
https://github.com/bevyengine/bevy/tree/v0.7.0
83c6ffb
What you did
When trying to setup fallible systems, I had a case where one system needed exclusive access to the world, but could also error. Upon chaining it with an error handler I would get a compile error. Other exclusive systems that didn't refer to the world seemed to work. I'm new to rust so I couldn't exactly make sense of what the type errors was wanting from me. Below is a minimal repo case of the compile error:
// main.rs
use bevy::prelude::*;
struct DummyEvent;
fn exclusive_1(mut _writer: EventWriter<DummyEvent>) -> std::io::Result<()> {
Ok(())
}
fn exclusive_2(_world: &mut World) -> std::io::Result<()> {
Ok(())
}
fn error_handler(In(result): In<std::io::Result<()>>) {
//noop
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_event::<DummyEvent>()
.add_startup_system(exclusive_1.chain(error_handler).exclusive_system())
// compile error when using a different signature system
.add_startup_system(exclusive_2.chain(error_handler).exclusive_system())
.run();
}What went wrong
I was expecting systems that have the signature:
fn exclusive_2(_world: &mut World) -> std::io::Result<()> can be chained as exclusive systems, but the compiler suggests there are some trait bounds not being satisfied.
Additional information
Compiler error below:
error[E0599]: the method `chain` exists for fn item `for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}`, but its trait bounds were not satisfied
--> src\main.rs:23:41
|
23 | .add_startup_system(exclusive_2.chain(error_handler).exclusive_system())
| ^^^^^ method cannot be called on `for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}` due to unsatisfied trait bounds
|
= note: `exclusive_2` is a function, perhaps you wish to call it
= note: the following trait bounds were not satisfied:
`for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: IntoSystem<(), _, _>`
which is required by `for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: bevy::prelude::IntoChainSystem<_, _, _, _, _>`
`&for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: IntoSystem<(), _, _>`
which is required by `&for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: bevy::prelude::IntoChainSystem<_, _, _, _, _>`
`&mut for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: IntoSystem<(), _, _>`
which is required by `&mut for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: bevy::prelude::IntoChainSystem<_, _, _, _, _>`
`for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: Iterator`
which is required by `&mut for<'r> fn(&'r mut bevy::prelude::World) -> Result<(), std::io::Error> {exclusive_2}: Iterator`
For more information about this error, try `rustc --explain E0599`.
error: could not compile `chain-repo` due to previous error