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
Required Associated Constants§
Required Methods§
sourcefn try_from_versioned(tagged: AnyVersion<T>) -> Result<Self, VersionMismatch>
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 {}),
);