kui-derive
#[derive(Message)] for kui: a Rust enum or struct to and from the
plain-data payload a kui message is.
kui carries every message as a Value map shaped {kind, ...fields}, so
one view model serves Rust, Lua, C and Node alike. This derive lets a Rust
app keep a typed enum instead: widgets::button(ui, "Save", Msg::Save)
sends it and ev.message::<Msg>() reads it back. Most apps get the derive
through kui-native (use kui_native::Message; cargo feature derive, on
by default) and never name this crate.
Install
Only a crate that depends on kui-core alone needs this crate directly:
cargo add kui-derive, then #[message(crate = "kui_core")] on each type.
Example
use widgets;
use ;
The derive generates From<Msg> for Value, TryFrom<Value> (with a
MessageError naming what did not fit) and MessageField, so a message
can be a field of another. #[message(string)] on an enum of unit
variants encodes it as a bare string instead of a map.
Where it fits
| Crate | What it is |
|---|---|
| kui-native | The windowed runner most apps use; re-exports this derive |
| kui-core | The model, layout, widgets and events, no window |
| kui-wgpu | The GPU renderer |
| kui-derive | This crate |
| kui-lua, kui-ffi | Lua and C bindings; kui-node is the Node.js binding, on npm |
Documentation
- API: https://docs.rs/kui-derive
- The book: https://kui-book.qxuken.dev
- Repository: https://github.com/qxuken/kui
License
MIT