Skip to main content

Migrate

Trait Migrate 

Source
pub trait Migrate: Document {
    // Provided method
    fn migrate(dynamic: Dynamic, from_version: u32) -> Result<Self> { ... }
}
Expand description

Static-dispatch shim trait so crate::codec::decode can write <T as Migrate>::migrate(...) without taking T: Migrate as an explicit bound on top of T: Document.

Migrate is implemented for every T: Document via the blanket impl below, which forwards to the inherent method Document::migrate. Concrete types customise migration by overriding Document::migrate (which has a default erroring body); they do NOT need to touch Migrate directly.

The separation exists for two reasons:

  1. Rust does not have stable specialisation, so a blanket impl Migrate for T cannot coexist with concrete impl Migrate for MyType overrides. Putting the override on the Document trait (a single, non-blanket impl per type) sidesteps the conflict.
  2. Keeping Migrate as a thin shim trait preserves the issue-#36 surface area (the codec calls <T as Migrate>::migrate(...)) without forcing a separate impl Migrate for ... block at every Document site.

§Errors

Propagates the override’s errors. The default body returns Error::SchemaMigrationNotImplemented.

Provided Methods§

Source

fn migrate(dynamic: Dynamic, from_version: u32) -> Result<Self>

Migrate an older stored record into the current Self type.

Forwards to Document::migrate; see that method for the contract.

§Errors

Propagates Document::migrate’s errors verbatim. The default body returns Error::SchemaMigrationNotImplemented.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Document> Migrate for T