Skip to main content

calimero_version/
lib.rs

1use std::borrow::Cow;
2use std::fmt;
3use std::sync::LazyLock;
4
5#[cfg(test)]
6mod tests;
7
8static CURRENT: LazyLock<CalimeroVersion<'static>> = LazyLock::new(|| CalimeroVersion {
9    release: env!("CARGO_PKG_VERSION").into(),
10    build: env!("CALIMERO_BUILD").into(),
11    commit: env!("CALIMERO_COMMIT").into(),
12    rustc: env!("CALIMERO_RUSTC_VERSION").into(),
13});
14
15static CURRENT_STRING: LazyLock<String> = LazyLock::new(|| CURRENT.to_string());
16
17#[derive(Clone)]
18pub struct CalimeroVersion<'a> {
19    pub release: Cow<'a, str>,
20    pub build: Cow<'a, str>,
21    pub commit: Cow<'a, str>,
22    pub rustc: Cow<'a, str>,
23}
24
25impl CalimeroVersion<'static> {
26    pub fn current() -> Self {
27        CURRENT.clone()
28    }
29
30    pub fn current_str() -> &'static str {
31        &*CURRENT_STRING
32    }
33}
34
35impl fmt::Display for CalimeroVersion<'_> {
36    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
37        write!(
38            f,
39            "(release {}) (build {}) (commit {}) (rustc {})",
40            self.release, self.build, self.commit, self.rustc,
41        )
42    }
43}