Skip to main content

IntoMsg

Trait IntoMsg 

Source
pub trait IntoMsg<Msg>: Sized {
    // Required method
    fn defer(work: impl Fn() -> Self + 'static) -> Msg;
}
Expand description

What a handler’s result can be turned into, so a widget’s setter takes both shapes: a closure that returns the widget’s message type, and — in an application built from components — one that just does the work and returns nothing.

let checked = Rc::new(Cell::new(false));
let flag = checked.clone();
// the closure does the work; there is no message to return
let _box: Checkbox = Checkbox::new(false).on_toggle(move |on| flag.set(on));

A closure that returns () becomes a message that runs it: the work waits for the message to be delivered, not for it to be made, because a widget may ask for its message more than once for one interaction. Anything else is its own message, made at once.

Required Methods§

Source

fn defer(work: impl Fn() -> Self + 'static) -> Msg

The message that stands for work’s result.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl IntoMsg<Callback> for ()

Source§

fn defer(work: impl Fn() + 'static) -> Callback

Implementors§

Source§

impl<Msg> IntoMsg<Msg> for Msg