pub struct Spec {
pub schema: String,
pub root: String,
pub elements: HashMap<String, Element>,
pub title: Option<TitleBinding>,
pub layout: Option<String>,
pub data: Value,
}Expand description
Top-level v2 JSON-UI document.
A Spec is a flat element map keyed by ID with a single root pointer.
Children are referenced by string ID, not by nesting, which keeps the
structure human-auditable and preserves a stable anchor for every element.
Fields§
§schema: StringSchema version tag ("ferro-json-ui/v2").
root: StringID of the root element (must exist as a key in elements).
elements: HashMap<String, Element>Flat map of element ID to element body. Element IDs are
^[A-Za-z_][A-Za-z0-9_-]{0,127}$.
title: Option<TitleBinding>Optional document title (used by layouts to populate <title>).
Accepts a literal string or {"$data": "/path"} binding.
layout: Option<String>Optional layout name (e.g. "dashboard", "app").
data: ValueArbitrary data payload consumed by data-path references inside elements.
Implementations§
Source§impl Spec
impl Spec
Sourcepub fn builder() -> SpecBuilder
pub fn builder() -> SpecBuilder
Entry point for fluent construction of a Spec.
The first .element(id, _) call sets the root if it has not been
explicitly set via .root(). The terminal .build() runs the same
structural validation as Spec::from_json.
Sourcepub fn merge_data(self, handler_data: Value) -> Self
pub fn merge_data(self, handler_data: Value) -> Self
Merge handler-provided data into spec.data via a shallow top-level merge.
If handler_data is a JSON Object, its keys are inserted into self.data,
overwriting matching keys (handler wins — locked per 119-CONTEXT D-04).
If self.data is Value::Null (the default for specs built without .data(...)),
it is initialized to an empty object before inserting — otherwise as_object_mut()
would return None and the handler keys would be silently dropped
(119-RESEARCH §Pitfall 4).
If handler_data is not an Object (Null, Array, String, Number, Bool), it is
silently ignored — a debug_assert! fires in dev builds but production never
panics (119-CONTEXT D-04).
Consuming builder (mut self -> Self) for consistency with SpecBuilder.