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
+9 -2
View File
@@ -17,6 +17,10 @@ use std::process::Command;
use std::time::Duration;
use std::time::Instant;
mod defaults {
pub const DATA_REFRESH_INTERVAL: u64 = 10;
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct BatteryConfig {
@@ -24,7 +28,8 @@ pub struct BatteryConfig {
pub enable: bool,
/// Hide the widget if the battery is at full charge
pub hide_on_full_charge: Option<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>,
@@ -34,7 +39,9 @@ pub struct BatteryConfig {
impl From<BatteryConfig> for Battery {
fn from(value: BatteryConfig) -> Self {
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
let data_refresh_interval = value
.data_refresh_interval
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
Self {
enable: value.enable,
+9 -2
View File
@@ -16,12 +16,17 @@ 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))]
pub struct CpuConfig {
/// Enable the Cpu 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>,
@@ -31,7 +36,9 @@ pub struct CpuConfig {
impl From<CpuConfig> for Cpu {
fn from(value: CpuConfig) -> Self {
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
let data_refresh_interval = value
.data_refresh_interval
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
Self {
enable: value.enable,
+8 -5
View File
@@ -21,15 +21,18 @@ use windows::Win32::UI::Input::KeyboardAndMouse::GetKeyboardLayout;
use windows::Win32::UI::WindowsAndMessaging::GetForegroundWindow;
use windows::Win32::UI::WindowsAndMessaging::GetWindowThreadProcessId;
const DEFAULT_DATA_REFRESH_INTERVAL: u64 = 1;
const ERROR_TEXT: &str = "Error";
mod defaults {
pub const DATA_REFRESH_INTERVAL: u64 = 10;
pub const ERROR_TEXT: &str = "Error";
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct KeyboardConfig {
/// Enable the Input widget
pub enable: bool,
/// Data refresh interval (default: 1 second)
/// Data refresh interval
#[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>,
@@ -39,7 +42,7 @@ impl From<KeyboardConfig> for Keyboard {
fn from(value: KeyboardConfig) -> Self {
let data_refresh_interval = value
.data_refresh_interval
.unwrap_or(DEFAULT_DATA_REFRESH_INTERVAL);
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
Self {
enable: value.enable,
@@ -124,7 +127,7 @@ fn get_active_keyboard_layout() -> eyre::Result<String, ()> {
fn get_lang() -> String {
get_active_keyboard_layout()
.map(|l| l.trim_end_matches('\0').to_string())
.unwrap_or_else(|_| ERROR_TEXT.to_string())
.unwrap_or_else(|_| defaults::ERROR_TEXT.to_string())
}
impl Keyboard {
+9 -2
View File
@@ -16,12 +16,17 @@ 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))]
pub struct MemoryConfig {
/// Enable the Memory 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>,
@@ -31,7 +36,9 @@ pub struct MemoryConfig {
impl From<MemoryConfig> for Memory {
fn from(value: MemoryConfig) -> Self {
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
let data_refresh_interval = value
.data_refresh_interval
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
Self {
enable: value.enable,
+9 -2
View File
@@ -24,6 +24,10 @@ use std::time::Duration;
use std::time::Instant;
use sysinfo::Networks;
mod defaults {
pub const DATA_REFRESH_INTERVAL: u64 = 10;
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct NetworkConfig {
@@ -40,7 +44,8 @@ pub struct NetworkConfig {
/// Characters to reserve for received and transmitted activity
#[serde(alias = "network_activity_fill_characters")]
pub activity_left_padding: Option<usize>,
/// 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>,
@@ -64,7 +69,9 @@ pub struct NetworkSelectConfig {
impl From<NetworkConfig> for Network {
fn from(value: NetworkConfig) -> Self {
let default_refresh_interval = 10;
let data_refresh_interval = value.data_refresh_interval.unwrap_or(10);
let data_refresh_interval = value
.data_refresh_interval
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
Self {
enable: value.enable,
+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(),
+1 -1
View File
@@ -92,7 +92,7 @@ pub struct TimeConfig {
///}
/// ```
pub timezone: Option<String>,
/// Change the icon depending on the time. The default icon is used between 8:30 and 12:00. (default: false)
/// Change the icon depending on the time. The default icon is used between 8:30 and 12:00
pub changing_icon: Option<bool>,
}
+9 -2
View File
@@ -14,12 +14,17 @@ use std::process::Command;
use std::time::Duration;
use std::time::Instant;
mod defaults {
pub const DATA_REFRESH_INTERVAL: u64 = 12;
}
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
pub struct UpdateConfig {
/// Enable the Update widget
pub enable: bool,
/// Data refresh interval (default: 12 hours)
/// Data refresh interval in hours
#[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>,
@@ -27,7 +32,9 @@ pub struct UpdateConfig {
impl From<UpdateConfig> for Update {
fn from(value: UpdateConfig) -> Self {
let data_refresh_interval = value.data_refresh_interval.unwrap_or(12);
let data_refresh_interval = value
.data_refresh_interval
.unwrap_or(defaults::DATA_REFRESH_INTERVAL);
let mut latest_version = String::new();