diff --git a/Cargo.toml b/Cargo.toml index f4f5a7d..2fd30ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "versionize_derive" -version = "0.1.1" +version = "0.1.2" license = "Apache-2.0" authors = ["Amazon Firecracker team "] description = "Implements the Versionize derive proc macro." diff --git a/src/descriptors/struct_desc.rs b/src/descriptors/struct_desc.rs index dbeac4d..78fc578 100644 --- a/src/descriptors/struct_desc.rs +++ b/src/descriptors/struct_desc.rs @@ -71,8 +71,12 @@ impl Descriptor for StructDescriptor { // Generate code to map the app version to struct version and wrap the // deserializers with the `version` match. + let current_version = self.version(); quote! { let version = version_map.get_type_version(app_version, ::type_id()); + if app_version == version_map.latest_version() && version != #current_version { + return Err(VersionizeError::VersionMapNotUpdated); + } match version { #versioned_deserializers _ => panic!("Unknown {:?} version {}.", ::type_id(), version) diff --git a/src/descriptors/union_desc.rs b/src/descriptors/union_desc.rs index 9a5723e..9fc3f24 100644 --- a/src/descriptors/union_desc.rs +++ b/src/descriptors/union_desc.rs @@ -40,8 +40,12 @@ impl Descriptor for UnionDescriptor { }); } + let current_version = self.version(); quote! { let version = version_map.get_type_version(app_version, Self::type_id()); + if app_version == version_map.latest_version() && version != #current_version { + return Err(VersionizeError::VersionMapNotUpdated); + } match version { #versioned_deserializers _ => panic!("Unknown {:?} version {}.", Self::type_id(), version) diff --git a/src/lib.rs b/src/lib.rs index d479149..bd42d0d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,9 +50,13 @@ pub fn impl_versionize(input: TokenStream) -> proc_macro::TokenStream { let version = descriptor.version(); let versioned_serializer = descriptor.generate_serializer(); let deserializer = descriptor.generate_deserializer(); + let current_version = version; let serializer = quote! { // Get the struct version for the input app_version. let version = version_map.get_type_version(app_version, ::type_id()); + if app_version == version_map.latest_version() && version != #current_version { + return Err(VersionizeError::VersionMapNotUpdated); + } // We will use this copy to perform semantic serialization. let mut copy_of_self = self.clone(); match version {