Skip to content

Commit

Permalink
Add zarrs::version::version_{str,pre}
Browse files Browse the repository at this point in the history
  • Loading branch information
LDeakin committed Nov 16, 2024
1 parent 01aaafb commit 2e3ea68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 15 additions & 1 deletion zarrs/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}

0 comments on commit 2e3ea68

Please sign in to comment.