use anyhow::Result; use serde::{Deserialize, Serialize}; use std::{fs::File, io::Write}; pub const COMMAND_COUNT: usize = 8; #[derive(Debug, Serialize, Deserialize)] pub struct Config { pub commands: [Option; COMMAND_COUNT], } impl Config { pub fn open(path: &str) -> Result { Ok(serde_json::from_str(&std::fs::read_to_string(path)?)?) } pub fn save(&self, path: &str) -> Result<()> { let mut file = File::create(path)?; let s = serde_json::to_string(self)?; write!(file, "{}", s)?; Ok(()) } } impl Default for Config { fn default() -> Config { Config { commands: Default::default(), } } }