http_server_plugin/
config.rs1use std::fs::read_to_string;
2use std::path::PathBuf;
3
4use anyhow::{bail, Result};
5use serde::de::DeserializeOwned;
6use toml::Table;
7
8pub fn read_from_path<T: DeserializeOwned>(path: PathBuf, key: &str) -> Result<T> {
9 let config_str = read_to_string(&path)?;
10 let config_tbl: Table = toml::from_str(&config_str)?;
11
12 if let Some(tbl) = config_tbl.get(key) {
13 let config: T = tbl.to_owned().try_into().unwrap();
14 return Ok(config);
15 }
16
17 bail!("Key not found")
18}