Module versionize::version_map
source · Expand description
A helper to map struct and enum versions to a sequence of root versions. This helper is required to support the versioning of a hierarchy of structures composed of individually versioned structures or enums.
extern crate versionize;
extern crate versionize_derive;
use versionize::{VersionMap, Versionize, VersionizeResult};
use versionize_derive::Versionize;
#[derive(Versionize)]
pub struct Struct1 {
a: u32,
#[version(start = 2)]
b: u8,
}
#[derive(Versionize)]
pub struct Struct2 {
x: u32,
#[version(start = 2)]
y: u8,
}
#[derive(Versionize)]
pub struct State {
struct1: Struct1,
struct2: Struct2,
}
let mut version_map = VersionMap::new(); //
version_map
.new_version()
.set_type_version(Struct1::type_id(), 2)
.new_version()
.set_type_version(Struct2::type_id(), 2);
// Check that there are 3 root versions.
assert_eq!(version_map.latest_version(), 3);
// Check that root version 1 has all structs at version 1.
assert_eq!(version_map.get_type_version(1, Struct1::type_id()), 1);
assert_eq!(version_map.get_type_version(1, Struct2::type_id()), 1);
assert_eq!(version_map.get_type_version(1, State::type_id()), 1);
// Check that root version 2 has Struct1 at version 2 and Struct2
// at version 1.
assert_eq!(version_map.get_type_version(2, Struct1::type_id()), 2);
assert_eq!(version_map.get_type_version(2, Struct2::type_id()), 1);
assert_eq!(version_map.get_type_version(2, State::type_id()), 1);
// Check that root version 3 has Struct1 and Struct2 at version 2.
assert_eq!(version_map.get_type_version(3, Struct1::type_id()), 2);
assert_eq!(version_map.get_type_version(3, Struct2::type_id()), 2);
assert_eq!(version_map.get_type_version(3, State::type_id()), 1);
Structs
- The VersionMap API provides functionality to define the version for each type and attach them to specific root versions.
Traits
- Trait to check whether is specific
version
is supported by aVersionMap
.