gateway_common/config/
toml.rs

1use serde_json::json;
2use toml::Value;
3
4use crate::error::BoxError;
5
6pub fn get_toml_by_context<'a, T: serde::Deserialize<'a>>(toml_context: &str) -> Result<T, BoxError> {
7    // 解析 TOML 文件内容
8    let parsed_toml: Value = toml_context.parse()?;
9    let json = json!(parsed_toml);
10    Ok(T::deserialize(json).map_err(|e| format!("toml to json error {:?}", e))?)
11}