Module panicking_methods

Source
Expand description

Checks for use of panicking methods of World when a non-panicking alternative exists.

For instance, this will lint against World::entity(), recommending that World::get_entity() should be used instead.

§Motivation

Panicking is the nuclear option of error handling in Rust: it is meant for cases where recovery is near-impossible. As such, panicking is usually undesirable in long-running applications and games like what Bevy is used for. This lint aims to prevent unwanted crashes in these applications by forcing developers to handle the Option or Result in their code.

§Example

#[derive(Resource)]
struct MyResource;

fn panicking_world(world: &mut World) {
    let resource = world.resource::<MyResource>();
    // ...
}

Use instead:


#[derive(Resource)]
struct MyResource;

fn graceful_world(world: &mut World) {
    let Some(resource) = world.get_resource::<MyResource>() else {
        // Resource may not exist.
        return;
    };

    // ...
}

Structs§

PanickingMethods

Statics§

PANICKING_METHODS
Click me for more information.