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
@@ -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,