From 16650a2ca16f001705b230fbb1f27f57fdbafca5 Mon Sep 17 00:00:00 2001 From: Penwing Date: Sat, 27 Jan 2024 22:39:25 +0100 Subject: [PATCH] general paths --- src/tools/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 92a3133..4eeaa35 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -28,10 +28,10 @@ pub struct AppState { pub theme: usize, } -pub fn save_state(state: &AppState, file_path: &str) -> Result<(), std::io::Error> { +pub fn save_state(state: &AppState, file_path: &Path) -> Result<(), std::io::Error> { let serialized_state = serde_json::to_string(state)?; - if let Some(parent_dir) = Path::new(file_path).parent() { + if let Some(parent_dir) = file_path.parent() { fs::create_dir_all(parent_dir)?; } @@ -43,12 +43,12 @@ pub fn save_state(state: &AppState, file_path: &str) -> Result<(), std::io::Erro file.write_all(serialized_state.as_bytes())?; - println!("Saved state at {}", file_path); + println!("Saved state at {}", file_path.display()); Ok(()) } -pub fn load_state(file_path: &str) -> Result { +pub fn load_state(file_path: &Path) -> Result { let serialized_state = read_to_string(file_path)?; Ok(serde_json::from_str(&serialized_state)?)