Expand description
Typed messages over the plain-data payload.
Payloads are Values so that Lua, C and JSX share them. A Rust app
gets an exhaustive match back with #[derive(Message)] (from
kui-derive, re-exported by kui-native and, behind the derive
feature, by this crate): it turns an enum into a {kind, ...fields}
map and back, so on_click(Msg::Save) builds the payload and
UiEvent::message::<Msg>() reads it.
ⓘ
// Needs the `derive` feature (on by default in kui-native).
#[derive(kui::Message)]
enum Msg {
Save,
Rename { to: String },
}
fn update(ev: &kui::UiEvent) {
match ev.message::<Msg>() {
Some(Msg::Save) => { /* ... */ }
Some(Msg::Rename { to }) => { /* ... */ }
None => {}
}
}The derive is built from MessageField, the conversion each field’s
type has, and MessageError, what a payload that is not one of the
enum’s says. Both are plain enough to implement by hand for a type the
derive does not cover.
Enums§
- Message
Error - Why a payload is not the message it was read as.
Traits§
- Message
Field - A type a message field can hold: to a
Valueand back. Implemented for the numbers,bool,String,Valueitself,Option(absent or null isNone) andVec;#[derive(Message)]implements it for the type it derives, so one message can carry another.