Skip to content

Commit

Permalink
refactor version matching logic
Browse files Browse the repository at this point in the history
  • Loading branch information
washanhanzi committed Nov 16, 2024
1 parent 62b41a6 commit 9c0b612
Show file tree
Hide file tree
Showing 12 changed files with 477 additions and 339 deletions.
62 changes: 62 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ cargo-audit = { git = "https://github.com/washanhanzi/rustsec", branch = "main",
cargo-lock = { git = "https://github.com/washanhanzi/rustsec", branch = "main", version = "10.0.1", features = [
"dependency-tree",
] }
chrono = "0.4.38"

[features]
default = []
Expand Down
23 changes: 11 additions & 12 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ use once_cell::sync::Lazy;
use serde::Deserialize;
use std::sync::RwLock;

use crate::decoration::DecorationFormatter;
use crate::decoration::{CompiledFormatter, DecorationFormatter};

#[derive(Default, Debug, Deserialize, Clone)]
#[derive(Default, Debug, Clone)]
pub struct Config {
pub decoration_formatter: CompiledFormatter,
}

#[derive(Default, Debug, Deserialize, Clone)]
pub struct UserConfig {
#[serde(flatten)]
pub renderer: RendererConfig,
}
Expand All @@ -19,15 +24,9 @@ pub struct RendererConfig {

pub static GLOBAL_CONFIG: Lazy<RwLock<Config>> = Lazy::new(|| RwLock::new(Config::default()));

pub fn initialize_config(mut config: Config) {
let mut global_config = GLOBAL_CONFIG.write().unwrap();
*global_config = config;
}

pub fn update_config<F>(update_fn: F)
where
F: FnOnce(&mut Config),
{
pub fn initialize_config(config: UserConfig) {
let mut global_config = GLOBAL_CONFIG.write().unwrap();
update_fn(&mut global_config);
*global_config = Config {
decoration_formatter: config.renderer.decoration_formatter.compile(),
};
}
Loading

0 comments on commit 9c0b612

Please sign in to comment.