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:
- Rust does not have stable specialisation, so a blanket
impl Migrate for Tcannot coexist with concreteimpl Migrate for MyTypeoverrides. Putting the override on theDocumenttrait (a single, non-blanket impl per type) sidesteps the conflict. - Keeping
Migrateas a thin shim trait preserves the issue-#36 surface area (the codec calls<T as Migrate>::migrate(...)) without forcing a separateimpl Migrate for ...block at everyDocumentsite.
§Errors
Propagates the override’s errors. The default body returns
Error::SchemaMigrationNotImplemented.
Provided Methods§
Sourcefn migrate(dynamic: Dynamic, from_version: u32) -> Result<Self>
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".