1use std::fmt;
4
5pub struct CommitInfo {
7 pub short_commit_hash: &'static str,
8 pub commit_hash: &'static str,
9 pub commit_date: &'static str,
10}
11
12pub struct VersionInfo {
14 pub version: &'static str,
16 pub release_channel: Option<&'static str>,
20 pub commit_info: Option<CommitInfo>,
24}
25
26impl fmt::Display for VersionInfo {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 write!(f, "{}", self.version)?;
29
30 if let Some(ci) = &self.commit_info {
31 write!(f, " ({} {})", ci.short_commit_hash, ci.commit_date)?;
32 };
33 Ok(())
34 }
35}
36
37pub const fn version() -> VersionInfo {
39 let version = match option_env!("CFG_RELEASE") {
40 Some(x) => x,
41 None => "0.0.0",
42 };
43
44 let release_channel = option_env!("CFG_RELEASE_CHANNEL");
45 let commit_info = match (
46 option_env!("RA_COMMIT_SHORT_HASH"),
47 option_env!("RA_COMMIT_HASH"),
48 option_env!("RA_COMMIT_DATE"),
49 ) {
50 (Some(short_commit_hash), Some(commit_hash), Some(commit_date)) => {
51 Some(CommitInfo { short_commit_hash, commit_hash, commit_date })
52 }
53 _ => None,
54 };
55
56 VersionInfo { version, release_channel, commit_info }
57}