comtrya_lib/contexts/variable_include/
file.rs1use std::collections::HashMap;
2
3use anyhow::Result;
4use reqwest::Url;
5use toml::Value;
6
7pub fn toml_values(url: &Url, contexts: &mut HashMap<String, String>) -> Result<()> {
8 let path = url.path();
9
10 let contents = std::fs::read_to_string(path)?;
11 let values: HashMap<String, Value> = toml::from_str(&contents)?;
12
13 for (key, value) in values {
14 contexts.insert(key.to_string(), value.to_string());
15 }
16
17 Ok(())
18}
19
20pub fn yaml_values(url: &Url, contexts: &mut HashMap<String, String>) -> Result<()> {
21 let path = url.path();
22
23 let contents = std::fs::read_to_string(path)?;
24 let values: HashMap<String, Value> = serde_yml::from_str(&contents)?;
25
26 for (key, value) in values {
27 contexts.insert(key.to_string(), value.to_string());
28 }
29
30 Ok(())
31}