Trait obake::VersionOf

source ·
pub trait VersionOf<T>: Into<AnyVersion<T>>where
    T: Versioned,{
    const VERSION: &'static str;

    // Required method
    fn try_from_versioned(
        tagged: AnyVersion<T>
    ) -> Result<Self, VersionMismatch>;
}
Expand description

Automatically implemented for all declared versions of a versioned data-structure.

Note

Not intended to be hand-implemented, use versioned to derive it.

Required Associated Constants§

source

const VERSION: &'static str

The semantic version number of this version.

Required Methods§

source

fn try_from_versioned(tagged: AnyVersion<T>) -> Result<Self, VersionMismatch>

Trys to convert the version-tagged representation of T into this particular version.

Errors

If tagged.version_str() != Self::VERSION, this conversion will fail and report a corresponding VersionMismatch.

use obake::VersionOf;

#[obake::versioned]
#[obake(version("0.1.0"))]
#[obake(version("0.2.0"))]
struct Foo {}


let x: obake::AnyVersion<Foo> = (Foo {}).into();
assert_eq!(
    <Foo!["0.1.0"]>::try_from_versioned(x),
    Err(obake::VersionMismatch {
        expected: "0.1.0",
        found: "0.2.0",
    }),
);

let x: obake::AnyVersion<Foo> = (Foo {}).into();
assert_eq!(
    <Foo!["0.2.0"]>::try_from_versioned(x),
    Ok(Foo {}),
);

Implementors§