pub trait ComponentController<C: Component> {
    // Required methods
    fn sender(&self) -> &Sender<C::Input>;
    fn state(&self) -> &StateWatcher<C>;
    fn widget(&self) -> &C::Root;
    fn detach_runtime(&mut self);

    // Provided methods
    fn emit(&self, event: C::Input) { ... }
    fn model(&self) -> Ref<'_, C> { ... }
    fn widgets(&self) -> Ref<'_, C::Widgets> { ... }
}
Expand description

Shared behavior of component controller types.

Required Methods§

source

fn sender(&self) -> &Sender<C::Input>

Provides access to the component’s sender.

source

fn state(&self) -> &StateWatcher<C>

Provides access to the state of a component.

source

fn widget(&self) -> &C::Root

Returns the root widget of the component.

source

fn detach_runtime(&mut self)

Dropping this type will usually stop the runtime of the component. With this method you can give the runtime a static lifetime. In other words, dropping the controller or connector will not stop the runtime anymore, instead it will run until the app is closed.

Provided Methods§

source

fn emit(&self, event: C::Input)

Emits an input to the component.

Examples found in repository?
examples/message_broker.rs (line 216)
210
211
212
213
214
215
216
217
218
219
    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
        match msg {
            AppMsg::SetMode(mode) => {
                self.mode = mode;
            }
            AppMsg::ShowDialog => {
                self.dialog.emit(DialogMsg::Show);
            }
        }
    }
More examples
Hide additional examples
examples/components.rs (line 211)
205
206
207
208
209
210
211
212
213
214
215
216
217
    fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
        match msg {
            AppMsg::SetMode(mode) => {
                self.mode = mode;
            }
            AppMsg::CloseRequest => {
                self.dialog.emit(DialogMsg::Show);
            }
            AppMsg::Close => {
                relm4::main_application().quit();
            }
        }
    }
source

fn model(&self) -> Ref<'_, C>

Returns a reference to the Component.

source

fn widgets(&self) -> Ref<'_, C::Widgets>

Returns a reference to the Component::Widgets.

Implementors§