Skip to main content

Message

Trait Message 

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.

A MessageReader system parameter tracks the consumption of these events on a per-system basis using a Local<MessageCursor>, which will guarantee each system an opportunity to read the event once.

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 ImeEvent
where Self: Send + Sync + 'static,

Source§

impl Message for TextEditRequest
where Self: Send + Sync + 'static,

Source§

impl Message for CommandQueueOverflow
where Self: Send + Sync + 'static,

Source§

impl Message for ClickEvent
where Self: Send + Sync + 'static,

Source§

impl Message for ClipboardRead
where Self: Send + Sync + 'static,

Source§

impl Message for CloseRequest
where Self: Send + Sync + 'static,

Source§

impl Message for DialogClosed
where Self: Send + Sync + 'static,

Source§

impl Message for DoubleClickEvent
where Self: Send + Sync + 'static,

Source§

impl Message for DragEndEvent
where Self: Send + Sync + 'static,

Source§

impl Message for DragMoveEvent
where Self: Send + Sync + 'static,

Source§

impl Message for DragStartEvent
where Self: Send + Sync + 'static,

Source§

impl Message for FileDropped
where Self: Send + Sync + 'static,

Source§

impl Message for FileHoverCancelled
where Self: Send + Sync + 'static,

Source§

impl Message for FileHovered
where Self: Send + Sync + 'static,

Source§

impl Message for FilePicked
where Self: Send + Sync + 'static,

Source§

impl Message for FocusedKey
where Self: Send + Sync + 'static,

Source§

impl Message for HotkeyFired
where Self: Send + Sync + 'static,

Source§

impl Message for HotkeyReleased
where Self: Send + Sync + 'static,

Source§

impl Message for KeyPressed
where Self: Send + Sync + 'static,

Source§

impl Message for KeyReleased
where Self: Send + Sync + 'static,

Source§

impl Message for LongPressEvent
where Self: Send + Sync + 'static,

Source§

impl Message for MenuClicked
where Self: Send + Sync + 'static,

Source§

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

Source§

impl Message for NotificationActionInvoked
where Self: Send + Sync + 'static,

Source§

impl Message for PointerLeft
where Self: Send + Sync + 'static,

Source§

impl Message for PointerMoved
where Self: Send + Sync + 'static,

Source§

impl Message for PointerPressed
where Self: Send + Sync + 'static,

Source§

impl Message for PointerReleased
where Self: Send + Sync + 'static,

Source§

impl Message for ShowContextMenu
where Self: Send + Sync + 'static,

Source§

impl Message for TextInputCommitted
where Self: Send + Sync + 'static,

Source§

impl Message for TrayClicked
where Self: Send + Sync + 'static,

Source§

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

Source§

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

Source§

impl Message for ImeSurroundingRequested
where Self: Send + Sync + 'static,

Source§

impl Message for ImeSurroundingResponse
where Self: Send + Sync + 'static,

Source§

impl Message for TextEditApplied
where Self: Send + Sync + 'static,

Source§

impl Message for TextEditRejected
where Self: Send + Sync + 'static,

§

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