Skip to main content

ctl10n/
toml_parser.rs

1use std::collections::HashMap;
2use crate::error::{Result, Error::TOMLStructureError};
3
4pub fn parse_toml(toml: &str) -> Result<HashMap<String, String>> {
5    let toml_value = toml.parse::<toml::Value>()?;
6
7    if let toml::Value::Table(table) = toml_value {
8        table
9            .into_iter()
10            .map(|(key, value)| {
11                if let toml::Value::String(string) = value {
12                    Ok((key, string))
13                } else {
14                    Err(TOMLStructureError)
15                }
16            })
17            .collect()
18    } else {
19        Err(TOMLStructureError)
20    }
21}