Skip to content

Commit

Permalink
fix(config): provide defaults for all config fields
Browse files Browse the repository at this point in the history
  • Loading branch information
myypo committed Aug 24, 2024
1 parent 0e1eb3c commit 969e1fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions compass/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,18 @@ pub fn set_config(conf: Config) {
#[derive(Debug, serde::Deserialize, Default, macros::FromLua)]
#[serde(default)]
pub struct Config {
#[serde(default)]
pub picker: PickerConfig,

#[serde(default)]
pub tracker: TrackerConfig,

#[serde(default)]
pub marks: MarksConfig,

#[serde(default)]
pub persistence: PersistenceConfig,

#[serde(default)]
pub frecency: FrecencyConfig,
}
30 changes: 24 additions & 6 deletions compass/src/config/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,38 @@ where

#[derive(Debug, Deserialize)]
pub struct Debounce {
#[serde(deserialize_with = "duration_from_millis")]
#[serde(default = "default_run", deserialize_with = "duration_from_millis")]
pub run: Duration,
#[serde(deserialize_with = "duration_from_millis")]
#[serde(
default = "default_maintenance",
deserialize_with = "duration_from_millis"
)]
pub maintenance: Duration,
#[serde(deserialize_with = "duration_from_millis")]
#[serde(
default = "default_activate",
deserialize_with = "duration_from_millis"
)]
pub activate: Duration,
}

fn default_run() -> Duration {
Duration::from_millis(200)
}

fn default_maintenance() -> Duration {
Duration::from_millis(500)
}

fn default_activate() -> Duration {
Duration::from_millis(3000)
}

impl Default for Debounce {
fn default() -> Self {
Self {
run: Duration::from_millis(200),
maintenance: Duration::from_millis(500),
activate: Duration::from_millis(3000),
run: default_run(),
maintenance: default_maintenance(),
activate: default_activate(),
}
}
}
Expand Down

0 comments on commit 969e1fb

Please sign in to comment.