From 9279f7516b5a08ad676b4b4bf6e5766247ba4fbc Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Sun, 23 Mar 2025 22:47:27 +0100 Subject: [PATCH] Update dependencies --- Cargo.toml | 44 ++++++++++++++++++++++---------------------- src/config.rs | 19 +++++++++++++++---- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a5ef4c0..84f962b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,22 +1,22 @@ -[package] -name = "rpi_keep_alive" -version = "0.1.0" -authors = ["Greg Burri "] -edition = "2024" - -[dependencies] -rand = "0.9" - -serde = { version = "1.0", features = ["derive"] } -serde_json = "1.0" -ron = "0.8" - -ping = "0.5" - -anyhow = "1" - -[profile.release] -codegen-units = 1 -strip = true -lto = true -panic = 'abort' +[package] +name = "rpi_keep_alive" +version = "0.1.0" +authors = ["Greg Burri "] +edition = "2024" + +[dependencies] +rand = "0.9" + +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +ron = "0.9" + +ping = "0.5" + +anyhow = "1" + +[profile.release] +codegen-units = 1 +strip = true +lto = true +panic = 'abort' diff --git a/src/config.rs b/src/config.rs index 09d81dd..879d7bc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,9 +1,12 @@ -use std::{fs::File, time::Duration}; +use std::{ + fs::{self, File}, + time::Duration, +}; use anyhow::Result; use ron::{ de::from_reader, - ser::{to_writer_pretty, PrettyConfig}, + ser::{PrettyConfig, to_string_pretty}, }; use serde::{Deserialize, Serialize}; @@ -26,9 +29,17 @@ impl Config { Ok(file) => from_reader(file).map_err(|e| e.into()), // The file doesn't exit -> create it with default values. Err(_) => { - let file = File::create(file_path)?; let default_config = Config::default(); - to_writer_pretty(file, &default_config, PrettyConfig::new())?; + + let ron_string = to_string_pretty(&default_config, PrettyConfig::new()) + .unwrap_or_else(|error| { + panic!("Failed to serialize ron configuration: {}", error) + }); + + fs::write(file_path, ron_string).unwrap_or_else(|error| { + panic!("Failed to write default configuration file: {}", error) + }); + Ok(default_config) } } -- 2.49.0