Struct relm4::MessageBroker

source ·
pub struct MessageBroker<C: Component> { /* private fields */ }
Expand description

A type that can be used in static variables to pass messages to components.

The primary use-case for this type is to communicate between components on different levels.

Imagine you have three components: A, B and C. A and B are children of the main application, but C is a child of B. If C wants to pass a message to A, it relies on B to forward that message to A. This is not great because B has nothing to do this message but has to implement additional logic only to pass the message through. MessageBroker allows you to use statics to remove this limitation.

Note

MessageBroker will not forward any messages until you initialize them with ComponentBuilder::launch_with_broker().

Only initialize the message broker once!

use relm4::{MessageBroker, Component};

static MY_COMPONENT: MessageBroker<MyComponent> = MessageBroker::new();

// Initialize the component and the message broker with `launch_with_broker`.
let controller = MyComponent::builder().launch_with_broker((), &MY_COMPONENT).detach();

Implementations§

Creates a new MessageBroker.

The returned message broker will not forward messages until it’s initialized.

Get the input sender of the component.

Send an input message to the component.

Trait Implementations§

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Returns the position. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Returns the position. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more