refactor(bar): inline defaults in schemars attrs

This commit is contained in:
LGUG2Z
2026-01-04 19:08:34 -08:00
parent b792328676
commit 1219c3d118
8 changed files with 30 additions and 87 deletions
+2 -8
View File
@@ -16,10 +16,6 @@ use std::time::Instant;
use sysinfo::RefreshKind;
use sysinfo::System;
mod defaults {
pub const DATA_REFRESH_INTERVAL: u64 = 10;
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
/// Memory widget configuration
@@ -27,7 +23,7 @@ pub struct MemoryConfig {
/// Enable the Memory widget
pub enable: bool,
/// Data refresh interval in seconds
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DATA_REFRESH_INTERVAL)))]
#[cfg_attr(feature = "schemars", schemars(extend("default" = 10)))]
pub data_refresh_interval: Option<u64>,
/// Display label prefix
pub label_prefix: Option<LabelPrefix>,
@@ -37,9 +33,7 @@ pub struct MemoryConfig {
impl From<MemoryConfig> for Memory {
fn from(value: MemoryConfig) -> Self {
let data_refresh_interval = value
.data_refresh_interval
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
Self {
enable: value.enable,