Skip to content

Commit a3d68ce

Browse files
committed
refactor(toml): Pull out table conversion
1 parent c548330 commit a3d68ce

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/file/format/toml.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::error::Error;
22

3-
use crate::format;
43
use crate::map::Map;
54
use crate::value::Value;
65

@@ -9,8 +8,18 @@ pub(crate) fn parse(
98
text: &str,
109
) -> Result<Map<String, Value>, Box<dyn Error + Send + Sync>> {
1110
// Parse a TOML value from the provided text
12-
let value = from_toml_value(uri, &toml::from_str(text)?);
13-
format::extract_root_table(uri, value)
11+
let table = from_toml_table(uri, &toml::from_str(text)?);
12+
Ok(table)
13+
}
14+
15+
fn from_toml_table(uri: Option<&String>, table: &toml::Table) -> Map<String, Value> {
16+
let mut m = Map::new();
17+
18+
for (key, value) in table {
19+
m.insert(key.clone(), from_toml_value(uri, value));
20+
}
21+
22+
m
1423
}
1524

1625
fn from_toml_value(uri: Option<&String>, value: &toml::Value) -> Value {
@@ -21,12 +30,7 @@ fn from_toml_value(uri: Option<&String>, value: &toml::Value) -> Value {
2130
toml::Value::Boolean(value) => Value::new(uri, value),
2231

2332
toml::Value::Table(ref table) => {
24-
let mut m = Map::new();
25-
26-
for (key, value) in table {
27-
m.insert(key.clone(), from_toml_value(uri, value));
28-
}
29-
33+
let m = from_toml_table(uri, table);
3034
Value::new(uri, m)
3135
}
3236

0 commit comments

Comments
 (0)