blob: 02af65c2c8dad677cc881b29ee34cd42e71398c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
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)
}
}
|