Message

Trait Message 

Source
pub trait Message:
    Send
    + Sync
    + 'static { }
Expand description

A buffered message for pull-based event handling.

Messages can be written with MessageWriter and read using the MessageReader system parameter. Messages are stored in the Messages<M> resource, and require periodically polling the world for new messages, typically in a system that runs as part of a schedule.

While the polling imposes a small overhead, messages are useful for efficiently batch processing a large number of messages at once. For cases like these, messages can be more efficient than Events (which are handled via Observers).

Unlike Events triggered for observers, messages are evaluated at fixed points in the schedule rather than immediately when they are sent. This allows for more predictable scheduling, and deferring message processing to a later point in time.

Messages must be thread-safe.

§Usage

The Message trait can be derived:

#[derive(Message)]
struct Greeting(String);

The message can then be written to the message buffer using a MessageWriter:

fn write_hello(mut writer: MessageWriter<Greeting>) {
    writer.write(Greeting("Hello!".to_string()));
}

Messages can be efficiently read using a MessageReader:

fn read_messages(mut reader: MessageReader<Greeting>) {
    // Process all messages of type `Greeting`.
    for Greeting(greeting) in reader.read() {
        println!("{greeting}");
    }
}

Implementors§

Source§

impl Message for GamepadEvent
where GamepadEvent: Send + Sync + 'static,

Source§

impl Message for GamepadRumbleRequest
where GamepadRumbleRequest: Send + Sync + 'static,

Source§

impl Message for RawGamepadEvent
where RawGamepadEvent: Send + Sync + 'static,

Source§

impl Message for AppLifecycle
where AppLifecycle: Send + Sync + 'static,

Source§

impl Message for WindowEvent
where WindowEvent: Send + Sync + 'static,

Source§

impl Message for AppExit
where AppExit: Send + Sync + 'static,

Source§

impl Message for FileDragAndDrop
where FileDragAndDrop: Send + Sync + 'static,

Source§

impl Message for Ime
where Ime: Send + Sync + 'static,

Source§

impl Message for ActionRequest
where ActionRequest: Send + Sync + 'static,

Source§

impl Message for UntypedAssetLoadFailedEvent

Source§

impl Message for RemovedComponentEntity
where RemovedComponentEntity: Send + Sync + 'static,

Source§

impl Message for GamepadAxisChangedEvent
where GamepadAxisChangedEvent: Send + Sync + 'static,

Source§

impl Message for GamepadButtonChangedEvent
where GamepadButtonChangedEvent: Send + Sync + 'static,

Source§

impl Message for GamepadButtonStateChangedEvent

Source§

impl Message for GamepadConnectionEvent
where GamepadConnectionEvent: Send + Sync + 'static,

Source§

impl Message for RawGamepadAxisChangedEvent

Source§

impl Message for RawGamepadButtonChangedEvent

Source§

impl Message for DoubleTapGesture
where DoubleTapGesture: Send + Sync + 'static,

Source§

impl Message for PanGesture
where PanGesture: Send + Sync + 'static,

Source§

impl Message for PinchGesture
where PinchGesture: Send + Sync + 'static,

Source§

impl Message for RotationGesture
where RotationGesture: Send + Sync + 'static,

Source§

impl Message for KeyboardFocusLost
where KeyboardFocusLost: Send + Sync + 'static,

Source§

impl Message for KeyboardInput
where KeyboardInput: Send + Sync + 'static,

Source§

impl Message for MouseButtonInput
where MouseButtonInput: Send + Sync + 'static,

Source§

impl Message for MouseMotion
where MouseMotion: Send + Sync + 'static,

Source§

impl Message for MouseWheel
where MouseWheel: Send + Sync + 'static,

Source§

impl Message for PointerHits
where PointerHits: Send + Sync + 'static,

Source§

impl Message for PointerInput
where PointerInput: Send + Sync + 'static,

Source§

impl Message for RequestRedraw
where RequestRedraw: Send + Sync + 'static,

Source§

impl Message for WindowBackendScaleFactorChanged

Source§

impl Message for WindowCloseRequested
where WindowCloseRequested: Send + Sync + 'static,

Source§

impl Message for WindowClosed
where WindowClosed: Send + Sync + 'static,

Source§

impl Message for WindowClosing
where WindowClosing: Send + Sync + 'static,

Source§

impl Message for WindowCreated
where WindowCreated: Send + Sync + 'static,

Source§

impl Message for WindowDestroyed
where WindowDestroyed: Send + Sync + 'static,

Source§

impl Message for WindowFocused
where WindowFocused: Send + Sync + 'static,

Source§

impl Message for WindowOccluded
where WindowOccluded: Send + Sync + 'static,

Source§

impl Message for WindowResized
where WindowResized: Send + Sync + 'static,

Source§

impl Message for WindowScaleFactorChanged
where WindowScaleFactorChanged: Send + Sync + 'static,

Source§

impl Message for WindowThemeChanged
where WindowThemeChanged: Send + Sync + 'static,

Source§

impl Message for RawWinitWindowEvent
where RawWinitWindowEvent: Send + Sync + 'static,

Source§

impl Message for WakeUp
where WakeUp: Send + Sync + 'static,

Source§

impl Message for CursorEntered
where CursorEntered: Send + Sync + 'static,

Source§

impl Message for CursorLeft
where CursorLeft: Send + Sync + 'static,

Source§

impl Message for CursorMoved
where CursorMoved: Send + Sync + 'static,

Source§

impl Message for TouchInput
where TouchInput: Send + Sync + 'static,

Source§

impl Message for WindowMoved
where WindowMoved: Send + Sync + 'static,

Source§

impl<A> Message for AssetEvent<A>
where A: Asset, AssetEvent<A>: Send + Sync + 'static,

Source§

impl<A> Message for AssetLoadFailedEvent<A>
where A: Asset, AssetLoadFailedEvent<A>: Send + Sync + 'static,

Source§

impl<E> Message for Pointer<E>
where E: Debug + Clone + Reflect, Pointer<E>: Send + Sync + 'static,