From 2e3ea683a3c765cb00742665cf7a3603141e57cf Mon Sep 17 00:00:00 2001 From: Lachlan Deakin Date: Sun, 17 Nov 2024 09:20:55 +1100 Subject: [PATCH] Add `zarrs::version::version_{str,pre}` --- CHANGELOG.md | 5 ++++- zarrs/src/version.rs | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 07ee5529..b3af2aef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added +- Add `zarrs::version::version_{str,pre}` + ### Changed -- Make `zarrs::version::version_{major,minor,patch}` const +- Make `zarrs::version::version_{,major,minor,patch}` const ## [0.18.0-beta.0] - 2024-11-15 diff --git a/zarrs/src/version.rs b/zarrs/src/version.rs index 23c60486..939ecf10 100644 --- a/zarrs/src/version.rs +++ b/zarrs/src/version.rs @@ -20,6 +20,12 @@ pub const fn version_patch() -> u32 { VERSION_PATCH } +/// The `zarrs` pre-release version. +#[must_use] +pub const fn version_pre() -> &'static str { + env!("CARGO_PKG_VERSION_PRE") +} + /// A [`u32`] representation of the `zarrs` version. /// /// Encoded as @@ -45,6 +51,14 @@ pub const fn version_patch() -> u32 { /// # assert!(version_patch == zarrs::version::version_patch()); /// ``` #[must_use] -pub fn version() -> u32 { +pub const fn version() -> u32 { (version_major() << 22) | (version_minor() << 12) | version_patch() } + +/// A string representation of the `zarrs` version. +/// +/// Matches the `CARGO_PKG_VERSION`. +#[must_use] +pub const fn version_str() -> &'static str { + env!("CARGO_PKG_VERSION") +}