diff --git a/Cargo.toml b/Cargo.toml index ad2dcf44f0..985dcbb79f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/distribution/version.rs b/src/distribution/version.rs index d5b8b63fb9..8fb5070173 100644 --- a/src/distribution/version.rs +++ b/src/distribution/version.rs @@ -1,3 +1,5 @@ +use const_format::formatcp; + /// API incompatible changes. pub const VERSION_MAJOR: u32 = 1; @@ -10,9 +12,15 @@ 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)] @@ -20,6 +28,7 @@ mod tests { use super::*; #[test] + #[allow(deprecated)] fn version_test() { assert_eq!(version(), "1.0.0-dev".to_string()) } diff --git a/src/image/version.rs b/src/image/version.rs index c0ec075956..9a7c4beb09 100644 --- a/src/image/version.rs +++ b/src/image/version.rs @@ -1,3 +1,5 @@ +use const_format::formatcp; + /// API incompatible changes. pub const VERSION_MAJOR: u32 = 1; @@ -10,9 +12,15 @@ 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)] @@ -20,6 +28,7 @@ mod tests { use super::*; #[test] + #[allow(deprecated)] fn version_test() { assert_eq!(version(), "1.0.1-dev".to_string()) } diff --git a/src/runtime/version.rs b/src/runtime/version.rs index 2753790d31..2290ad4c26 100644 --- a/src/runtime/version.rs +++ b/src/runtime/version.rs @@ -1,3 +1,5 @@ +use const_format::formatcp; + /// API incompatible changes. pub const VERSION_MAJOR: u32 = 1; @@ -10,9 +12,15 @@ 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)] @@ -20,6 +28,7 @@ mod tests { use super::*; #[test] + #[allow(deprecated)] fn version_test() { assert_eq!(version(), "1.0.2-dev".to_string()) }