Skip to content

Commit

Permalink
Merge pull request #39 from EspressoSystems/fix/version-display
Browse files Browse the repository at this point in the history
Improve Display for Version
  • Loading branch information
jbearer authored Mar 29, 2024
2 parents 04e861d + bd81bd0 commit 50c93e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "vbs"
version = "0.1.3"
version = "0.1.4"
edition = "2021"
rust-version = "1.75.0"
authors = ["Espresso Systems <[email protected]>"]
Expand All @@ -12,7 +12,7 @@ license = "MIT"

[dependencies]
anyhow = "1.0"
derive_more = "0.99"
bincode = "1.3"
displaydoc = "0.2"
serde = { version = "1.0", features = ["derive"] }
serde_with = "3.4"
19 changes: 18 additions & 1 deletion src/version.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use anyhow::anyhow;
use core::fmt::Debug;
use displaydoc::Display;
use derive_more::Display;
use serde::{Deserialize, Serialize};

#[derive(Clone, Copy, Debug, Deserialize, Display, Eq, Hash, PartialEq, Serialize)]
/// Type for protocol version number
#[display(fmt = "{major}.{minor}")]
pub struct Version {
/// major version number
pub major: u16,
Expand Down Expand Up @@ -49,6 +50,7 @@ pub trait StaticVersionType: Sync + Send + Clone + Copy + Debug + private::Seale
}

#[derive(Clone, Copy, Display)]
#[display(fmt = "{MAJOR}.{MINOR}")]
pub struct StaticVersion<const MAJOR: u16, const MINOR: u16> {}

impl<const MAJOR: u16, const MINOR: u16> StaticVersionType for StaticVersion<MAJOR, MINOR> {
Expand Down Expand Up @@ -82,3 +84,18 @@ mod private {
// Implement for those same types, but no others.
impl<const MAJOR: u16, const MINOR: u16> Sealed for super::StaticVersion<MAJOR, MINOR> {}
}

#[cfg(test)]
mod test {
use super::*;

#[test]
fn test_version_display() {
assert_eq!("1.2", Version { major: 1, minor: 2 }.to_string());
}

#[test]
fn test_static_version_display() {
assert_eq!("1.2", StaticVersion::<1, 2> {}.to_string());
}
}

0 comments on commit 50c93e6

Please sign in to comment.