trunkver_lib/
lib.rs

1extern crate chrono;
2
3use chrono::Utc;
4use std::fmt;
5
6pub mod prelude {
7    pub use crate::TrunkVer;
8}
9
10pub struct TrunkVer {
11    pub build_ref: String,
12    pub time: String,
13    pub source_ref: String,
14}
15
16impl TrunkVer {
17    pub fn new(build_ref: &str, source_ref: &str, with_v: bool) -> Self {
18        let now_str = Utc::now().format("%Y%m%d%H%M%S").to_string();
19        let prefix = if with_v { "v" } else { "" };
20        let time = format!("{}{}.0.0", prefix, now_str);
21
22        Self {
23            build_ref: build_ref.into(),
24            time,
25            source_ref: source_ref.into(),
26        }
27    }
28}
29
30impl fmt::Display for TrunkVer {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        write!(f, "{}-{}-{}", self.time, self.source_ref, self.build_ref)
33    }
34}