From 119e9eef22e695fcde14c5c8478982884361e796 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Tue, 11 Jul 2023 10:21:43 +0300 Subject: [PATCH] fix toml save/load --- src/config.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index e75e4ee..a562ef0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -66,11 +66,12 @@ impl Default for Config { impl Config { const FILENAME: &'static str = "config.toml"; fn read>(path: P) -> Result { - let data = fs::read(path).map_err(|e| format!("can't read config: {:?}", e))?; - toml::from_slice(&data).map_err(|e| format!("can't parse config: {:?}", e)) + let data = fs::read_to_string(path).map_err(|e| format!("can't read config: {:?}", e))?; + toml::from_str(&data).map_err(|e| format!("can't parse config: {:?}", e)) } fn write>(&self, path: P) -> Result<(), String> { - let data = toml::to_vec(&self).map_err(|e| format!("can't serialize config: {:?}", e))?; + let data = toml::to_string_pretty(&self) + .map_err(|e| format!("can't serialize config: {:?}", e))?; fs::write(path, &data).map_err(|e| format!("can't write config: {:?}", e)) } fn file_location() -> Result {