Skip to main content

json_model

Macro json_model 

Source
macro_rules! json_model {
    ($ty:ty => named) => { ... };
    ($ty:ty => $schema:tt, $field_type:ident) => { ... };
    ($($ty:ty),* $(,)?) => { ... };
}
Expand description

Implements Model (and Settable) for serde types stored whole as one JSON string, last writer wins: values with no meaningful concurrent merge (a tone curve, a keyframe track). The types need Serialize, Deserialize, Default (the value of an absent slot) and PartialEq holding only between values of equal JSON forms, as a derived one does: the edits between two copies compare each value in memory, and serialise only the ones that differ.

A type whose JSON form is one value of a known type names its schema and its FieldType variant (json_model!(ResetDay => {"type": "integer"}, Int)): its setter then takes that value, and a surface publishes the field as that type. A type that also derives JsonSchema publishes the record that schema describes (json_model!(TabletConfig => named)), so a view reads its fields rather than an opaque value.