Function bevy_ecs::system::adapter::unwrap

source ·
pub fn unwrap<T, E: Debug>(In: In<Result<T, E>>) -> T
Expand description

System adapter that unwraps the Ok variant of a Result. This is useful for fallible systems that should panic in the case of an error.

There is no equivalent adapter for Option. Instead, it’s best to provide an error message and convert to a Result using ok_or{_else}.

Examples

Panicking on error

use bevy_ecs::prelude::*;

// Building a new schedule/app...
let mut sched = Schedule::default();
sched.add_system(
        // Panic if the load system returns an error.
        load_save_system.pipe(system_adapter::unwrap)
    )
    // ...

// A system which may fail irreparably.
fn load_save_system() -> Result<(), std::io::Error> {
    let save_file = open_file("my_save.json")?;
    dbg!(save_file);
    Ok(())
}