Skip to content

Commit 73e4304

Browse files
committed
refactor: from_gura_value (json5 referenced)
Now adapted to the better approach handled by json5 equivalent method. - DRY, avoid the value wrapper reptition via storing the match value and using a final return afterwards to value wrap: `Value::new(uri, vk)`. - Object and Array kinds now adopt the json5 iter + collect approach. Additionally corrects the `Cargo.toml` feature `ura` to `gura`. As the feature name conflicts with the equivalent dependency name, the feature needs to prefix the dependency with `dep:`, removing the need for the package to include `pacakge = "gura"`. Signed-off-by: Brennan Kinney <[email protected]>
1 parent 04254a8 commit 73e4304

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ json = ["serde_json"]
2020
yaml = ["yaml-rust"]
2121
ini = ["rust-ini"]
2222
json5 = ["json5_rs", "serde/derive"]
23-
ura = ["gura"]
23+
gura = ["dep:gura"]
2424
convert-case = ["convert_case"]
2525
preserve_order = ["indexmap", "toml?/preserve_order", "serde_json?/preserve_order", "ron?/indexmap"]
2626
async = ["async-trait"]
@@ -37,7 +37,7 @@ yaml-rust = { version = "0.4", optional = true }
3737
rust-ini = { version = "0.19", optional = true }
3838
ron = { version = "0.8", optional = true }
3939
json5_rs = { version = "0.4", optional = true, package = "json5" }
40-
gura = { version = "0.5", optional = true, package = "gura" }
40+
gura = { version = "0.5", optional = true }
4141
indexmap = { version = "2.0.0", features = ["serde"], optional = true }
4242
convert_case = { version = "0.6", optional = true }
4343
pathdiff = "0.2"

src/file/format/gura.rs

+23-22
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,38 @@ pub fn parse(
1818
}
1919

2020
fn from_gura_value(uri: Option<&String>, value: GuraType) -> Value {
21-
match value {
22-
GuraType::String(value) => Value::new(uri, ValueKind::String(value)),
21+
let vk = match value {
22+
GuraType::String(value) => ValueKind::String(value),
2323

24-
GuraType::Integer(value) => Value::new(uri, ValueKind::I64(value as i64)),
25-
GuraType::BigInteger(value) => Value::new(uri, ValueKind::I128(value)),
26-
GuraType::Float(value) => Value::new(uri, ValueKind::Float(value)),
24+
GuraType::Integer(value) => ValueKind::I64(value as i64),
25+
GuraType::BigInteger(value) => ValueKind::I128(value),
26+
GuraType::Float(value) => ValueKind::Float(value),
2727

28-
GuraType::Bool(value) => Value::new(uri, ValueKind::Boolean(value)),
28+
GuraType::Bool(value) => ValueKind::Boolean(value),
2929

3030
GuraType::Object(table) => {
31-
let mut m = Map::new();
31+
let m = table
32+
.into_iter()
33+
.map(|(k, v)| (k, from_gura_value(uri, v)))
34+
.collect();
3235

33-
for (key, value) in table {
34-
m.insert(key, from_gura_value(uri, value));
35-
}
36-
37-
Value::new(uri, ValueKind::Table(m))
36+
ValueKind::Table(m)
3837
}
3938

4039
GuraType::Array(array) => {
41-
let mut l = Vec::new();
42-
43-
for value in array {
44-
l.push(from_gura_value(uri, value));
45-
}
40+
let l = array
41+
.into_iter()
42+
.map(|v| from_gura_value(uri, v))
43+
.collect();
4644

47-
Value::new(uri, ValueKind::Array(l))
45+
ValueKind::Array(l)
4846
}
4947

50-
// Null or remaining types (only intended for internal use):
51-
GuraType::Null => Value::new(uri, ValueKind::Nil),
52-
_ => Value::new(uri, ValueKind::Nil),
53-
}
48+
GuraType::Null => ValueKind::Nil,
49+
50+
// Remaining types (only intended for internal use):
51+
_ => ValueKind::Nil,
52+
};
53+
54+
Value::new(uri, vk)
5455
}

0 commit comments

Comments
 (0)