pub struct StateSpec { /* private fields */ }Expand description
A validated, shareable SystemState layout.
StateSpec owns an Arc to immutable metadata, making Clone a cheap
reference-count increment. Every state derived from a specification shares
the exact field order and name lookup table.
Implementations§
Source§impl StateSpec
impl StateSpec
Sourcepub fn load(path: impl AsRef<Path>) -> Result<Self, StateError>
pub fn load(path: impl AsRef<Path>) -> Result<Self, StateError>
Loads and validates a state specification from a JSON template.
The file is read as bytes and parsed directly, avoiding an intermediate
UTF-8 String allocation. The returned specification retains the input
path for diagnostics and provenance but does not canonicalize it or keep
the file open.
§Errors
Returns:
StateError::TemplateReadwhen the file cannot be read;StateError::TemplateParsewhen JSON syntax or structure is invalid;StateError::EmptyFieldNamefor an empty normalized field name;StateError::DuplicateFieldfor repeated normalized names;StateError::EmptyTypeTagfor an empty normalized type tag.
Sourcepub fn empty(&self, time: TimePoint) -> SystemState
pub fn empty(&self, time: TimePoint) -> SystemState
Creates an empty SystemState that shares this specification.
Every declared field exists in the returned state’s layout, while every payload slot starts empty. Cloning the specification is constant-time and does not duplicate layout data.
Sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
Converts this specification into a pretty-printed JSON template.
The generated document has the same strict fields structure accepted
by StateSpec::load. Runtime-only field indices and the source path
are omitted: field indices are reconstructed from array order, and the
destination path becomes the source when the JSON is loaded again.
Serialization borrows the immutable field slice and does not clone field names or type tags.
§Errors
Returns the underlying serde_json::Error if JSON serialization
fails.
Sourcepub fn source(&self) -> &Path
pub fn source(&self) -> &Path
Returns the path from which this specification was loaded.
The path is retained exactly as supplied to StateSpec::load. It may
be relative and is not guaranteed to remain accessible after loading.
Sourcepub fn fields(&self) -> &[FieldSpec]
pub fn fields(&self) -> &[FieldSpec]
Returns field definitions in deterministic template order.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Reports whether the template declares no fields.
Empty templates are structurally valid. They can represent a time-bearing event stream whose payload schema will be extended in a later template revision.