20 lines
534 B
Rust

#![allow(dead_code)]
use std::fs;
use std::path::Path;
use anyhow::{Context, Result};
use crate::data::config::AppConfig;
/// Load application configuration from a TOML file.
pub fn load_from_path(path: &Path) -> Result<AppConfig> {
let raw = fs::read_to_string(path)
.with_context(|| format!("failed to read configuration file at {}", path.display()))?;
let config = toml::from_str::<AppConfig>(&raw)
.with_context(|| format!("failed to parse configuration file {}", path.display()))?;
Ok(config)
}