utils/version.rs
1//! Contains the functionality to calculate the current Cargo version and make it available
2//! to the rest of the application through a `semver` `Version`.
3use semver::Version;
4use std::sync::LazyLock;
5
6/// Internal static reference to the parsed current version.
7///
8/// *Remark*: I considered making this a `const` instead of `static`, but then we'd have to either
9/// somehow do the const parsing ourselves, or hardcode it in a `Version::new` call and risk having it
10/// out of date with Cargo's version.
11static VERSION: LazyLock<Version, fn() -> Version> = LazyLock::<Version>::new(|| {
12 Version::parse(env!("CARGO_PKG_VERSION")).expect("invalid semver version")
13});
14
15/// Returns the `Version` of the software as defined in the workspace.
16#[must_use]
17pub fn version() -> &'static Version {
18 &VERSION
19}