// Status file management // // Writes a JSON status snapshot to data_dir/daemon-status.json. // Applications provide their own status struct (must impl Serialize). use std::fs; use std::path::Path; fn status_path(data_dir: &Path) -> std::path::PathBuf { data_dir.join("daemon-status.json") } /// Write a status snapshot to the status file. pub fn write(data_dir: &Path, status: &S) { if let Ok(json) = serde_json::to_string_pretty(status) { let _ = fs::write(status_path(data_dir), json); } } /// Read the status file as a string. pub fn read(data_dir: &Path) -> Option { fs::read_to_string(status_path(data_dir)).ok() } /// Read and deserialize the status file. pub fn load(data_dir: &Path) -> Option { let s = read(data_dir)?; serde_json::from_str(&s).ok() }