Skip to main content

Migration

Trait Migration 

Source
pub trait Migration: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn apply(&self, toml_src: &str) -> Result<MigrationResult, MigrateError>;
}
Expand description

A single idempotent config migration step.

Each impl wraps one of the free-standing migrate_* functions and gives it a stable name used in logs and test assertions. The trait is object-safe so that steps can be stored in a Vec<Box<dyn Migration + Send + Sync>>.

§Contract for implementors

  • apply must be idempotent: calling it twice on the same source must return the same output as calling it once.
  • On a no-op (nothing to migrate), apply returns a MigrationResult with changed_count == 0.

§Examples

use zeph_config::migrate::{Migration, MIGRATIONS};

// The registry is ordered chronologically; apply each step in sequence.
let mut toml = "[agent]\nname = \"zeph\"\n".to_owned();
for m in MIGRATIONS.iter() {
    toml = m.apply(&toml).expect("migration failed").output;
}

Required Methods§

Source

fn name(&self) -> &'static str

Human-readable identifier used in diagnostics and ordering assertions.

Source

fn apply(&self, toml_src: &str) -> Result<MigrationResult, MigrateError>

Apply this migration step to toml_src.

§Errors

Propagates any MigrateError from the underlying free function.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§