aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2024-09-19 22:09:20 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2024-09-19 22:09:20 +0200
commiteec01c9b72feff9533477014881b982124ca7b6d (patch)
tree084586316e04f01f48b479de0cb41113639ac8d5 /src/config.rs
downloadodr-dabmux-gui-eec01c9b72feff9533477014881b982124ca7b6d.tar.gz
odr-dabmux-gui-eec01c9b72feff9533477014881b982124ca7b6d.tar.bz2
odr-dabmux-gui-eec01c9b72feff9533477014881b982124ca7b6d.zip
Create project
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..3e0571d
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1,36 @@
+use std::fs;
+use anyhow::Context;
+use serde::{Deserialize, Serialize};
+
+
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct Config {
+ pub name: String,
+}
+
+impl Default for Config {
+ fn default() -> Self {
+ Config {
+ name: "CHANGEME".to_owned(),
+ }
+ }
+}
+
+const CONFIGFILE : &str = "odr-dabmux-gui-config.toml";
+
+impl Config {
+ pub fn load() -> anyhow::Result<Self> {
+ if std::path::Path::new(CONFIGFILE).exists() {
+ let file_contents = fs::read_to_string(CONFIGFILE)?;
+ toml::from_str(&file_contents).context("parsing config file")
+ }
+ else {
+ Ok(Default::default())
+ }
+ }
+
+ pub fn store(&self) -> anyhow::Result<()> {
+ fs::write(CONFIGFILE, toml::to_string_pretty(&self)?)
+ .context("writing config file")
+ }
+}