1mod load;
6
7use std::{fs, io, path::PathBuf};
8
9use schemars::JsonSchema;
10use serde::{Serialize, de::DeserializeOwned};
11
12pub use load::{LoadConfigError, try_load};
13
14pub trait ConfigFile: Default + DeserializeOwned + Serialize + JsonSchema {
16 fn config_file_path() -> PathBuf;
18
19 fn delete(&self) -> io::Result<()> {
21 fs::remove_file(Self::config_file_path())
22 }
23
24 fn write(&self) -> io::Result<()> {
26 let json = serde_json::to_string_pretty(self).map_err(io::Error::other)?;
27 fs::write(Self::config_file_path(), json)
28 }
29}