Module insert_event_resource

Source
Expand description

Checks for the Events<T> resource being manually inserted with App::init_resource() or App::insert_resource() instead of with App::add_event().

§Motivation

Unless you have intentionally and knowingly initialized the Events<T> resource in this way, events and their resources should be initialized with App::add_event() because it automatically handles dropping old events. Just adding Events<T> makes no such guarantee, and will likely result in a memory leak.

For more information, please see the documentation on App::add_event() and Events<T>.

§Example

#[derive(Event)]
struct MyEvent;

fn plugin(app: &mut App) {
    app.init_resource::<Events<MyEvent>>();
}

Use instead:

#[derive(Event)]
struct MyEvent;

fn plugin(app: &mut App) {
    app.add_event::<MyEvent>();
}

Structs§

InsertEventResource

Statics§

INSERT_EVENT_RESOURCE
Click me for more information.