Skip to main content

fedimint_core/
version.rs

1/// Get the  cargo package version of `fedimint-core`
2pub fn cargo_pkg() -> &'static str {
3    env!("CARGO_PKG_VERSION")
4}
5
6/// Get the `x.y.z` cargo release version of `fedimint-core`.
7pub fn cargo_pkg_release() -> &'static str {
8    release_version(cargo_pkg())
9}
10
11/// Return only the `x.y.z` release component of a cargo package version.
12pub fn release_version(version: &str) -> &str {
13    version
14        .split(['-', '+'])
15        .next()
16        .expect("split always returns at least one item")
17}
18
19/// Get the git hash version of `fedimint-core`
20///
21/// Note, in certain situations this not be accurate (eg. might be all `0`s).
22///
23/// The return value was injected via `fedimint-build` crate at the compile
24/// time.
25pub fn git_hash() -> &'static str {
26    option_env!("FEDIMINT_BUILD_CODE_VERSION").unwrap_or("0000000000000000000000000000000000000001")
27}
28
29/// Returns the version hash if it is meaningful (i.e. not all zeros, which
30/// `fedimint-build` substitutes when no git information is available).
31pub fn non_zero_version_hash(hash: &str) -> Option<&str> {
32    if hash.bytes().all(|b| b == b'0') {
33        None
34    } else {
35        Some(hash)
36    }
37}
38
39#[cfg(test)]
40mod tests;