agent_config/toml/file.rs
1use std::{fs, path::Path};
2
3use serde::de::DeserializeOwned;
4
5use crate::error::ConfigError;
6
7/// Read and deserialize one TOML configuration file.
8pub fn read_toml<T: DeserializeOwned>(path: impl AsRef<Path>) -> Result<T, ConfigError> {
9 let path = path.as_ref();
10 let contents = fs::read_to_string(path).map_err(|source| ConfigError::Io {
11 path: path.to_path_buf(),
12 source,
13 })?;
14
15 toml::from_str(&contents).map_err(|source| ConfigError::Parse {
16 path: path.to_path_buf(),
17 source,
18 })
19}