From a483cc97d56a770c4ccf91dfccf790a8c2d0c9fa Mon Sep 17 00:00:00 2001 From: Kim Altintop Date: Wed, 29 Mar 2023 13:20:08 +0200 Subject: core: version each metadata type separately It turns out to be preferable to be able to break one type without affecting the other. So instead of the global SpecVersion, use a separate FmtVersion for each type. For compatibility, keep supporting spec_version fields (until next major bump of the respective types' version). Signed-off-by: Kim Altintop --- src/metadata.rs | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) (limited to 'src/metadata.rs') diff --git a/src/metadata.rs b/src/metadata.rs index 9caee96..2da268f 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -56,13 +56,9 @@ pub use identity::{ }; #[derive(Clone, Eq, Ord, PartialEq, PartialOrd)] -pub struct SpecVersion(SemVer); - -impl SpecVersion { - pub const fn current() -> Self { - Self::new(0, 1, 0) - } +pub struct FmtVersion(SemVer); +impl FmtVersion { const fn new(major: u32, minor: u32, patch: u32) -> Self { Self(SemVer { major, @@ -92,19 +88,13 @@ impl SpecVersion { } } -impl Default for SpecVersion { - fn default() -> Self { - Self::current() - } -} - -impl fmt::Display for SpecVersion { +impl fmt::Display for FmtVersion { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.0.fmt(f) } } -impl FromStr for SpecVersion { +impl FromStr for FmtVersion { type Err = ::Err; fn from_str(s: &str) -> Result { @@ -112,7 +102,7 @@ impl FromStr for SpecVersion { } } -impl<'a> TryFrom<&'a str> for SpecVersion { +impl<'a> TryFrom<&'a str> for FmtVersion { type Error = >::Error; fn try_from(value: &str) -> Result { @@ -120,13 +110,13 @@ impl<'a> TryFrom<&'a str> for SpecVersion { } } -impl AsRef for SpecVersion { +impl AsRef for FmtVersion { fn as_ref(&self) -> &SemVer { &self.0 } } -impl serde::Serialize for SpecVersion { +impl serde::Serialize for FmtVersion { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -135,7 +125,7 @@ impl serde::Serialize for SpecVersion { } } -impl<'de> serde::Deserialize<'de> for SpecVersion { +impl<'de> serde::Deserialize<'de> for FmtVersion { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, -- cgit v1.2.3