docs(config): encode defaults of unwrapped options into schema

This commit ensures that the various default values that the different
Option<T> config properties can be unwrapped to are encoded by schemars
so that they can be picked up by docgen.
This commit is contained in:
LGUG2Z
2025-12-26 18:16:55 -08:00
parent 66c5766848
commit a42e809ade
13 changed files with 709 additions and 396 deletions
+21 -6
View File
@@ -16,18 +16,27 @@ use std::time::Duration;
use std::time::Instant;
use sysinfo::Disks;
mod defaults {
pub const DATA_REFRESH_INTERVAL: u64 = 10;
pub const SHOW_READ_ONLY_DISKS: bool = false;
pub const SHOW_REMOVABLE_DISKS: bool = true;
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct StorageConfig {
/// Enable the Storage widget
pub enable: bool,
/// Data refresh interval (default: 10 seconds)
/// Data refresh interval in seconds
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::DATA_REFRESH_INTERVAL)))]
pub data_refresh_interval: Option<u64>,
/// Display label prefix
pub label_prefix: Option<LabelPrefix>,
/// Show disks that are read only. (default: false)
/// Show disks that are read only
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::SHOW_READ_ONLY_DISKS)))]
pub show_read_only_disks: Option<bool>,
/// Show removable disks. (default: true)
/// Show removable disks
#[cfg_attr(feature = "schemars", schemars(extend("default" = defaults::SHOW_REMOVABLE_DISKS)))]
pub show_removable_disks: Option<bool>,
/// Select when the current percentage is over this value [[1-100]]
pub auto_select_over: Option<u8>,
@@ -40,10 +49,16 @@ impl From<StorageConfig> for Storage {
Self {
enable: value.enable,
disks: Disks::new_with_refreshed_list(),
data_refresh_interval: value.data_refresh_interval.unwrap_or(10),
data_refresh_interval: value
.data_refresh_interval
.unwrap_or(defaults::DATA_REFRESH_INTERVAL),
label_prefix: value.label_prefix.unwrap_or(LabelPrefix::IconAndText),
show_read_only_disks: value.show_read_only_disks.unwrap_or(false),
show_removable_disks: value.show_removable_disks.unwrap_or(true),
show_read_only_disks: value
.show_read_only_disks
.unwrap_or(defaults::SHOW_READ_ONLY_DISKS),
show_removable_disks: value
.show_removable_disks
.unwrap_or(defaults::SHOW_REMOVABLE_DISKS),
auto_select_over: value.auto_select_over.map(|o| o.clamp(1, 100)),
auto_hide_under: value.auto_hide_under.map(|o| o.clamp(1, 100)),
last_updated: Instant::now(),