diff options
author | Hristo Venev <hristo@venev.name> | 2019-05-17 19:29:04 +0300 |
---|---|---|
committer | Hristo Venev <hristo@venev.name> | 2019-05-18 19:31:47 +0300 |
commit | 780a0076255afb192ffd55d2c3ec46e4b93b0700 (patch) | |
tree | e147efa5ed0f6b274700e62549e87900cd6b106f /src/config.rs | |
parent | 81dc38168d7b0375673067435834146a499b5959 (diff) |
Implement command-line config parsing.
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/config.rs b/src/config.rs index bfa6342..9972830 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,10 +23,20 @@ pub struct Source { pub struct PeerConfig { #[serde(default = "default_min_keepalive")] pub min_keepalive: u32, - #[serde(default)] + #[serde(default = "default_max_keepalive")] pub max_keepalive: u32, } +impl Default for PeerConfig { + #[inline] + fn default() -> Self { + Self { + min_keepalive: default_min_keepalive(), + max_keepalive: default_max_keepalive(), + } + } +} + #[serde(deny_unknown_fields)] #[derive(serde_derive::Serialize, serde_derive::Deserialize, Clone, PartialEq, Eq, Debug)] pub struct UpdateConfig { @@ -35,8 +45,17 @@ pub struct UpdateConfig { pub refresh_sec: u32, } +impl Default for UpdateConfig { + #[inline] + fn default() -> Self { + Self { + refresh_sec: default_refresh_sec(), + } + } +} + #[serde(deny_unknown_fields)] -#[derive(serde_derive::Serialize, serde_derive::Deserialize, Clone, Debug)] +#[derive(serde_derive::Serialize, serde_derive::Deserialize, Default, Clone, Debug)] pub struct Config { pub cache_directory: Option<PathBuf>, pub runtime_directory: Option<PathBuf>, @@ -64,11 +83,16 @@ impl PeerConfig { } #[inline] -fn default_min_keepalive() -> u32 { +const fn default_min_keepalive() -> u32 { 10 } #[inline] -fn default_refresh_sec() -> u32 { +const fn default_max_keepalive() -> u32 { + 0 +} + +#[inline] +const fn default_refresh_sec() -> u32 { 1200 } |