use std::path::PathBuf; use tokio::fs::File; use tokio::io::AsyncWriteExt; use super::raw::RawConfig; /// This is the config struct used by most of the code, which is an interpreted version of the RawConfig struct which is the raw disk-representation of the config. pub(crate) struct Config { raw: RawConfig, root_dir: PathBuf, } impl Config { pub(crate) fn new>(root_dir: P) -> Result> { Ok(Config { raw: RawConfig::default(), root_dir: root_dir.into(), }) } pub(crate) async fn write_to_disk(&self) -> Result<(), Box> { let mut config_file = File::create(self.get_path_to_config_file()).await?; config_file .write_all(toml::to_string(&self.raw)?.as_bytes()) .await?; Ok(()) } pub(crate) fn get_path_to_config_file(&self) -> PathBuf { self.root_dir.join("writer.toml") } }