pub struct PayloadSchema { /* private fields */ }Expand description
A current schema version and optional migration from older stored JSON.
Migrations run only when versions differ. They must be deterministic, perform no external side effects, and avoid including secrets in errors. The runtime deserializes the returned JSON into the current Rust type; stored historical payloads remain unchanged.
Implementations§
Source§impl PayloadSchema
impl PayloadSchema
Sourcepub fn new(version: u32) -> Self
pub fn new(version: u32) -> Self
Uses version for newly serialized payloads. Legacy rows are version 1.
Sourcepub fn migrate(
self,
migration: impl Fn(u32, Value) -> Result<Value, PayloadError> + Send + Sync + 'static,
) -> Self
pub fn migrate( self, migration: impl Fn(u32, Value) -> Result<Value, PayloadError> + Send + Sync + 'static, ) -> Self
Adds a migration receiving the stored version and JSON. Return an explicit error for versions the application cannot safely interpret.
Sourcepub fn decode(&self, stored: u32, value: Value) -> Result<Value, PayloadError>
pub fn decode(&self, stored: u32, value: Value) -> Result<Value, PayloadError>
Reads stored JSON, migrating it if needed. This does not update the record, its input fingerprint, or its authoritative effect status.
§Errors
PayloadError::UnsupportedVersion when no migration is available,
or an application migration error.