gitui/src/version.rs
Stephan Dilly dad8e8d43d cargo fmt: use hardtabs
since it does not support hard-whitespaces its the only way to make whitespaces consisitent and checked
2021-08-17 14:24:25 +02:00

35 lines
791 B
Rust

use std::{env, fmt};
/// version type
#[derive(Default)]
pub struct Version {
major: u32,
minor: u32,
patch: u32,
}
impl Version {
/// read version at compile time from env variables
pub fn new() -> Self {
let mut res = Self::default();
let major_str = env!("CARGO_PKG_VERSION_MAJOR");
if let Ok(major) = major_str.parse::<u32>() {
res.major = major;
}
let minor_str = env!("CARGO_PKG_VERSION_MINOR");
if let Ok(minor) = minor_str.parse::<u32>() {
res.minor = minor;
}
let patch_str = env!("CARGO_PKG_VERSION_PATCH");
if let Ok(patch) = patch_str.parse::<u32>() {
res.patch = patch;
}
res
}
}
impl fmt::Display for Version {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "v{}.{}.{}", self.major, self.minor, self.patch)
}
}