diff --git a/src/main.rs b/src/main.rs index 8f5a187..6276ab5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,24 +34,20 @@ fn main() -> Result<(), eframe::Error> { } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] +#[serde(default)] struct Options { - #[serde(default = "Options::default_mute")] mute: bool, - #[serde(default = "Options::default_fan_enabled")] fan_enabled: bool, - #[serde(default = "Options::default_volume")] volume: f32, } -impl Options { - fn default_mute() -> bool { - false - } - fn default_fan_enabled() -> bool { - true - } - fn default_volume() -> f32 { - 100.0 +impl Default for Options { + fn default() -> Self { + Self { + mute: false, + fan_enabled: true, + volume: 100.0, + } } } @@ -65,11 +61,7 @@ struct AltairEmulator { impl AltairEmulator { fn new(cc: &eframe::CreationContext<'_>, audio_tx: Sender) -> Self { let options = if cc.storage.unwrap().get_string("options").is_none() { - Options { - mute: false, - fan_enabled: true, - volume: 1.0, - } + Options::default() } else { eframe::get_value(cc.storage.unwrap(), "options").unwrap() };