Module insert_message_resource

Module insert_message_resource 

Source
Expand description

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

§Motivation

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

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

§Example

#[derive(Message)]
struct MyMessage;

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

Use instead:

#[derive(Message)]
struct MyMessage;

fn plugin(app: &mut App) {
    app.add_message::<MyMessage>();
}