pub trait VersionedState:
Sized
+ Serialize
+ DeserializeOwned {
// Required methods
fn schema_version(&self) -> SchemaVersion;
fn migrate_one_step(
self,
from: SchemaVersion,
to: SchemaVersion,
) -> Result<Self>;
// Provided methods
fn next_version(current: SchemaVersion) -> Option<SchemaVersion> { ... }
fn migrate(self, target: SchemaVersion) -> Result<Self> { ... }
}Expand description
Trait for types whose serialized representation carries a schema version and can be migrated forward to a newer version.
Implementors provide migrate_one_step, and the default migrate() method
walks through all intermediate versions automatically.
Required Methods§
Sourcefn schema_version(&self) -> SchemaVersion
fn schema_version(&self) -> SchemaVersion
Return the schema version this instance was created at.
Sourcefn migrate_one_step(
self,
from: SchemaVersion,
to: SchemaVersion,
) -> Result<Self>
fn migrate_one_step( self, from: SchemaVersion, to: SchemaVersion, ) -> Result<Self>
Perform a single version-to-version migration.
Implementors should match on (from, to) rather than branching on
from alone, ensuring every transition is explicitly handled.
Provided Methods§
Sourcefn next_version(current: SchemaVersion) -> Option<SchemaVersion>
fn next_version(current: SchemaVersion) -> Option<SchemaVersion>
The next schema version after current, if any.
Sourcefn migrate(self, target: SchemaVersion) -> Result<Self>
fn migrate(self, target: SchemaVersion) -> Result<Self>
Migrate this instance to target, stepping through intermediate
versions one at a time. Returns the fully migrated instance or an
error if a migration step fails.
If target <= self.schema_version() this is a no-op.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".