Skip to content

Commit

Permalink
fix(cfg):use shadow instead magic value
Browse files Browse the repository at this point in the history
  • Loading branch information
limuy2022 committed Apr 13, 2024
1 parent 84f77a8 commit 17342af
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! some constant values and configurations in trc
use crate::build::{self};
use std::{path::PathBuf, sync::OnceLock};

pub const MAIN_MODULE_NAME: &str = "main";
pub const FLOAT_OVER_FLOW_LIMIT: usize = 18;
pub const VERSION: &str = "0.0.1";
pub static VERSION_DESTRUCT: (u8, u8, u8) = (0, 0, 1);
pub const VERSION: &str = build::PKG_VERSION;

pub fn get_history_file() -> &'static Option<PathBuf> {
static PATH: OnceLock<Option<PathBuf>> = OnceLock::new();
Expand All @@ -24,3 +24,17 @@ pub fn get_history_file() -> &'static Option<PathBuf> {
Some(config_file)
})
}

pub fn get_version_destruct() -> &'static (u8, u8, u8) {
static VERSION_SPLIT: OnceLock<(u8, u8, u8)> = OnceLock::new();
VERSION_SPLIT.get_or_init(|| {
let tmp: Vec<u8> = VERSION
.split('.')
.map(|s| s.parse::<u8>().unwrap())
.collect();
match tmp.as_slice() {
[first, second, third] => (*first, *second, *third),
_ => panic!("version is not right"),
}
})
}

0 comments on commit 17342af

Please sign in to comment.