use std::path::Path;
use crate::VoxoraConfig;
use crate::error::ConfigError;
impl VoxoraConfig {
pub fn from_file(path: &Path) -> Result<Self, ConfigError> {
if !path.exists() {
return Err(ConfigError::FileNotFound(path.to_path_buf()));
}
let text = std::fs::read_to_string(path).map_err(|e| ConfigError::FileIo {
path: path.to_path_buf(),
message: "read_to_string".into(),
source: e,
})?;
Self::from_str(&text, path)
}
pub fn from_str(text: &str, path_for_errors: &Path) -> Result<Self, ConfigError> {
toml::from_str(text).map_err(|e| ConfigError::FileParse {
path: path_for_errors.to_path_buf(),
message: e.to_string(),
source: Box::new(e),
})
}
}