Skip to content

Commit

Permalink
Merge pull request #265 from MOZGIII/static-version
Browse files Browse the repository at this point in the history
Use const_format and provide version as static str
  • Loading branch information
flavio authored Jan 8, 2025
2 parents 7ac4047 + 0a9932d commit 756cb6f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ image = []
runtime = []

[dependencies]
const_format = "0.2"
serde = { version = "1.0.129", features = ["derive"] }
thiserror = "2.0.0"
serde_json = "1.0.66"
Expand Down
11 changes: 10 additions & 1 deletion src/distribution/version.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use const_format::formatcp;

/// API incompatible changes.
pub const VERSION_MAJOR: u32 = 1;

Expand All @@ -10,16 +12,23 @@ pub const VERSION_PATCH: u32 = 0;
/// Indicates development branch. Releases will be empty string.
pub const VERSION_DEV: &str = "-dev";

/// Retrieve the version as static str representation.
pub const VERSION: &str = formatcp!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}{VERSION_DEV}");

/// Retrieve the version as string representation.
///
/// Use [`VERSION`] instead.
#[deprecated]
pub fn version() -> String {
format!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}{VERSION_DEV}")
VERSION.to_owned()
}

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

#[test]
#[allow(deprecated)]
fn version_test() {
assert_eq!(version(), "1.0.0-dev".to_string())
}
Expand Down
11 changes: 10 additions & 1 deletion src/image/version.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use const_format::formatcp;

/// API incompatible changes.
pub const VERSION_MAJOR: u32 = 1;

Expand All @@ -10,16 +12,23 @@ pub const VERSION_PATCH: u32 = 1;
/// Indicates development branch. Releases will be empty string.
pub const VERSION_DEV: &str = "-dev";

/// Retrieve the version as static str representation.
pub const VERSION: &str = formatcp!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}{VERSION_DEV}");

/// Retrieve the version as string representation.
///
/// Use [`VERSION`] instead.
#[deprecated]
pub fn version() -> String {
format!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}{VERSION_DEV}")
VERSION.to_owned()
}

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

#[test]
#[allow(deprecated)]
fn version_test() {
assert_eq!(version(), "1.0.1-dev".to_string())
}
Expand Down
11 changes: 10 additions & 1 deletion src/runtime/version.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use const_format::formatcp;

/// API incompatible changes.
pub const VERSION_MAJOR: u32 = 1;

Expand All @@ -10,16 +12,23 @@ pub const VERSION_PATCH: u32 = 2;
/// Indicates development branch. Releases will be empty string.
pub const VERSION_DEV: &str = "-dev";

/// Retrieve the version as static str representation.
pub const VERSION: &str = formatcp!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}{VERSION_DEV}");

/// Retrieve the version as string representation.
///
/// Use [`VERSION`] instead.
#[deprecated]
pub fn version() -> String {
format!("{VERSION_MAJOR}.{VERSION_MINOR}.{VERSION_PATCH}{VERSION_DEV}")
VERSION.to_owned()
}

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

#[test]
#[allow(deprecated)]
fn version_test() {
assert_eq!(version(), "1.0.2-dev".to_string())
}
Expand Down

0 comments on commit 756cb6f

Please sign in to comment.