Skip to main content

Upgrader

Trait Upgrader 

Source
pub trait Upgrader {
    // Required methods
    fn upgrade(&self) -> Result<Box<dyn Upgrader>, UpgraderError>;
    fn as_any(&self) -> &dyn Any;

    // Provided method
    fn is_terminal(&self) -> bool { ... }
}
Expand description

A versioned config that upgrades itself one step toward the latest schema version. The latest version’s upgrade is a no-op that returns the receiver unchanged, which is how the upgrade walker detects completion.

Unlike the Go Upgrade(log *slog.Logger) (Upgrader, error), which can return the exact same pointer to signal termination, Rust’s ownership rules make returning “the same object” from &self awkward with a Box<dyn Upgrader> return type. The real implementation will need to settle this (e.g. via an enum of known versions, or an is_terminal() query) rather than pointer identity; see PORT_NOTES.md.

Required Methods§

Source

fn upgrade(&self) -> Result<Box<dyn Upgrader>, UpgraderError>

Source

fn as_any(&self) -> &dyn Any

Exposes self as &dyn Any, so a caller holding a Box<dyn Upgrader> at the end of an upgrade walk can downcast back to the concrete type it expects — the Rust equivalent of the Go original’s upgraded.(*latest.CaproniConfig) type assertion, since Rust trait objects need an explicit escape hatch (there is no built-in upcast from dyn Upgrader to dyn Any without this).

Provided Methods§

Source

fn is_terminal(&self) -> bool

Reports whether this value is already at the latest version, i.e. whether upgrade would be a no-op. This is the termination signal config::registry::walk uses instead of the Go original’s pointer-identity check (next == cfg): Rust’s Box<dyn Upgrader> return type has no equivalent “return the same object” signal, so the walker asks each value directly rather than comparing addresses. Defaults to false; only the latest version’s Upgrader impl overrides it.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§