diff --git a/Cargo.toml b/Cargo.toml index cb4c22b..1366e9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vbs" -version = "0.1.4" +version = "0.1.5" edition = "2021" rust-version = "1.75.0" authors = ["Espresso Systems "] diff --git a/src/binary_serializer.rs b/src/binary_serializer.rs index 194f346..9a6d791 100644 --- a/src/binary_serializer.rs +++ b/src/binary_serializer.rs @@ -15,17 +15,13 @@ pub trait BinarySerializer { // TODO: `Versioned` trait - fn serialize_no_version(value: &T) -> Result> - where - T: Serialize; + fn serialize_no_version(value: &T) -> Result>; fn deserialize_no_version<'a, T>(bytes: &'a [u8]) -> Result where T: Deserialize<'a>; - fn serialize(value: &T) -> Result> - where - T: Serialize; + fn serialize(value: &T) -> Result>; fn deserialize<'a, T>(bytes: &'a [u8]) -> Result where diff --git a/src/bincode_serializer.rs b/src/bincode_serializer.rs index ac3d397..a220723 100644 --- a/src/bincode_serializer.rs +++ b/src/bincode_serializer.rs @@ -12,10 +12,7 @@ pub struct BincodeSerializer(PhantomData); impl BinarySerializer for BincodeSerializer { const MAJOR: u16 = VER::MAJOR; const MINOR: u16 = VER::MINOR; - fn serialize_no_version(value: &T) -> Result> - where - T: Serialize, - { + fn serialize_no_version(value: &T) -> Result> { Ok(bincode::serialize(value)?) } @@ -26,10 +23,7 @@ impl BinarySerializer for BincodeSerializer { Ok(bincode::deserialize(bytes)?) } - fn serialize(value: &T) -> Result> - where - T: Serialize, - { + fn serialize(value: &T) -> Result> { let mut vec = Self::version().serialize(); bincode::serialize_into(vec.by_ref(), value)?; Ok(vec) @@ -80,17 +74,13 @@ pub trait VersionedBinarySerializer { // TODO: `Versioned` trait - fn serialize_no_version(value: &T) -> Result> - where - T: Serialize + Versioned; + fn serialize_no_version(value: &T) -> Result>; fn deserialize_no_version<'a, T>(bytes: &'a [u8]) -> Result where T: Deserialize<'a> + Versioned; - fn serialize(value: &T) -> Result> - where - T: Serialize + Versioned; + fn serialize(value: &T) -> Result>; fn deserialize<'a, T>(bytes: &'a [u8]) -> Result where @@ -103,10 +93,7 @@ impl VersionedBinarySerializer for VersionedBincodeSeria const MINOR: u16 = VER::MINOR; type StaticVersion = VER; - fn serialize_no_version(value: &T) -> Result> - where - T: Serialize + Versioned, - { + fn serialize_no_version(value: &T) -> Result> { #[allow(clippy::let_unit_value)] let _ = VersionChecker::::VERSION_MISMATCH; @@ -123,10 +110,7 @@ impl VersionedBinarySerializer for VersionedBincodeSeria Ok(bincode::deserialize(bytes)?) } - fn serialize(value: &T) -> Result> - where - T: Serialize + Versioned, - { + fn serialize(value: &T) -> Result> { #[allow(clippy::let_unit_value)] let _ = VersionChecker::::VERSION_MISMATCH; diff --git a/src/version.rs b/src/version.rs index f2ed797..9e5da58 100644 --- a/src/version.rs +++ b/src/version.rs @@ -3,7 +3,9 @@ use core::fmt::Debug; use derive_more::Display; use serde::{Deserialize, Serialize}; -#[derive(Clone, Copy, Debug, Deserialize, Display, Eq, Hash, PartialEq, Serialize)] +#[derive( + Clone, Copy, Debug, Deserialize, Display, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, +)] /// Type for protocol version number #[display(fmt = "{major}.{minor}")] pub struct Version { @@ -89,6 +91,24 @@ mod private { mod test { use super::*; + #[test] + fn test_compare_version() { + let v1 = Version { major: 1, minor: 3 }; + let v2 = Version { major: 1, minor: 2 }; + + assert!(v1 > v2); + + let v3 = Version { major: 2, minor: 3 }; + let v4 = Version { major: 1, minor: 3 }; + + assert!(v3 > v4); + + let v5 = Version { major: 2, minor: 2 }; + let v6 = Version { major: 1, minor: 3 }; + + assert!(v5 > v6); + } + #[test] fn test_version_display() { assert_eq!("1.2", Version { major: 1, minor: 2 }.to_string());