Expand description
Value: the plain-data payload type for everything that crosses an
event or binding boundary.
A click payload, a drag event’s fields, a readback for a script: all of
them are a Value, so Rust, Lua, Node and C see one shape. A Rust app
that wants an exhaustive match over its own payloads puts a typed
enum on top with message.
A crate of its own (ADR 0075, decision 3), so what has no kui core —
the data channel, the recording’s reader — speaks the same values;
kui-core re-exports all of it where it always was (kui_core::Value,
kui_core::json, kui_core::message). Features: lua, the
conversions to and from an mlua value ([lua]); derive,
#[derive(Message)] from kui-derive.
use kui_value::Value;
let v = Value::map([
("kind", Value::str("drag")),
("x", Value::from(1.5f32)),
("n", Value::from(4usize)),
("on", true.into()),
]);
assert_eq!(v.get_str("kind"), Some("drag"));
assert_eq!(v.get_f32("x"), Some(1.5));
assert_eq!(v.get_float("n"), Some(4.0)); // an int reads as a float
assert_eq!(v.get_str("x"), None); // the wrong type is None
assert_eq!(Value::from("save"), Value::Str("save".into()));Re-exports§
pub use message::MessageError;pub use message::MessageField;
Modules§
- json
- A strict JSON reader into
Value, for the files the core reads itself — a DTCG token file and its resolver (ADR 0062). RFC 8259 and nothing more: no comments, no trailing commas. An object keeps its keys in file order (aValue::Map), and a key given twice keeps the last value, as the DTCG resolver’s “last declaration wins” reads it. A number with no fraction or exponent that fits ani64is anValue::Int; anything else is aValue::Float. - message
- Typed messages over the plain-data payload.
Enums§
- Value
- A dynamically typed value: null, bool, int, float, string, list or an ordered string-keyed map. See the module docs for an example.