projects
/
rpi_keep_alive.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
54f6863
)
Update dependencies
master
author
Greg Burri
<greg.burri@gmail.com>
Sun, 23 Mar 2025 21:47:27 +0000
(22:47 +0100)
committer
Greg Burri
<greg.burri@gmail.com>
Sun, 23 Mar 2025 21:47:27 +0000
(22:47 +0100)
Cargo.toml
patch
|
blob
|
history
src/config.rs
patch
|
blob
|
history
diff --git
a/Cargo.toml
b/Cargo.toml
index
a5ef4c0
..
84f962b
100644
(file)
--- a/
Cargo.toml
+++ b/
Cargo.toml
@@
-1,22
+1,22
@@
-[package]
-name = "rpi_keep_alive"
-version = "0.1.0"
-authors = ["Greg Burri <greg.burri@gmail.com>"]
-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]
\r
+name = "rpi_keep_alive"
\r
+version = "0.1.0"
\r
+authors = ["Greg Burri <greg.burri@gmail.com>"]
\r
+edition = "2024"
\r
+
\r
+[dependencies]
\r
+rand = "0.9"
\r
+
\r
+serde = { version = "1.0", features = ["derive"] }
\r
+serde_json = "1.0"
\r
+ron = "0.
9"
\r
+
\r
+ping = "0.5"
\r
+
\r
+anyhow = "1"
\r
+
\r
+[profile.release]
\r
+codegen-units = 1
\r
+strip = true
\r
+lto = true
\r
+panic = 'abort'
\r
diff --git
a/src/config.rs
b/src/config.rs
index
09d81dd
..
879d7bc
100644
(file)
--- 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,
use anyhow::Result;
use ron::{
de::from_reader,
- ser::{
to_writer_pretty, PrettyConfig
},
+ ser::{
PrettyConfig, to_string_pretty
},
};
use serde::{Deserialize, Serialize};
};
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(_) => {
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();
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)
}
}
Ok(default_config)
}
}