verso/config/load.rs
1use super::Config;
2use std::path::Path;
3
4pub fn from_path(path: &Path) -> anyhow::Result<Config> {
5 if !path.exists() {
6 return Ok(Config::default());
7 }
8 let text = std::fs::read_to_string(path)?;
9 let cfg: Config =
10 toml::from_str(&text).map_err(|e| anyhow::anyhow!("parsing {}: {}", path.display(), e))?;
11 Ok(cfg)
12}
13
14/// Deserialise from a TOML string. Used by tests.
15pub fn from_str(s: &str) -> anyhow::Result<Config> {
16 Ok(toml::from_str(s)?)
17}