pub struct Snapshot<T> {
pub format_version: u32,
pub model: T,
}Expand description
A versioned envelope around a serializable model state.
Versioning is centralized here so individual models do not need to duplicate format-version fields.
§Examples
use rill_ml::persistence::Snapshot;
use rill_ml::stats::Mean;
use rill_ml::OnlineStatistic;
let mut mean = Mean::new();
mean.update(1.0).unwrap();
mean.update(2.0).unwrap();
let snap = Snapshot::new(mean);
let json = serde_json::to_string(&snap).unwrap();
let restored: Snapshot<Mean> = serde_json::from_str(&json).unwrap();
let m = restored.into_model().unwrap();
assert!((m.value() - 1.5).abs() < 1e-12);Fields§
§format_version: u32The format version of this snapshot.
model: TThe model state.
Implementations§
Source§impl<T> Snapshot<T>
impl<T> Snapshot<T>
Sourcepub fn into_model(self) -> Result<T, RillError>
pub fn into_model(self) -> Result<T, RillError>
Consume the snapshot and return the model, verifying the format version.
Returns RillError::IncompatibleStateVersion if the version does not
match SNAPSHOT_FORMAT_VERSION.
Sourcepub fn into_model_with_validation<F>(self, validate: F) -> Result<T, RillError>
pub fn into_model_with_validation<F>(self, validate: F) -> Result<T, RillError>
Consume the snapshot, verify its format version, and run an application-provided model-state validator before returning the model.
The snapshot envelope can only validate its own version field because
T may be an application type. Use this method at trust boundaries to
enforce model-specific invariants before activating restored state.
§Errors
Returns RillError::IncompatibleStateVersion for a version mismatch,
or propagates the validator’s error.