Simplify default values for Options
This commit is contained in:
parent
3af5be3299
commit
a7ae967483
26
src/main.rs
26
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<AudioMessage>) -> 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()
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user