Skip to content

Commit 4140214

Browse files
committed
chore: Switch to serde_gura
- No `.unwrap()` concern now. - Leverage the common `from_parsed_value` method. - Greatly simplified format support. Signed-off-by: Brennan Kinney <[email protected]>
1 parent 0b781b8 commit 4140214

File tree

5 files changed

+8
-46
lines changed

5 files changed

+8
-46
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-
gura = ["dep:gura"]
23+
gura = ["serde_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 }
40+
serde_gura = { version = "0.1", 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

+3-41
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,14 @@
11
use std::error::Error;
22

3-
use gura::GuraType;
4-
53
use crate::format;
64
use crate::map::Map;
7-
use crate::value::{Value, ValueKind};
5+
use crate::value::Value;
86

97
pub fn parse(
108
uri: Option<&String>,
119
text: &str,
1210
) -> Result<Map<String, Value>, Box<dyn Error + Send + Sync>> {
13-
let value = from_gura_value(uri, gura::parse(text).unwrap());
11+
// Parse a Gura input from the provided text
12+
let value = format::from_parsed_value(uri, serde_gura::from_str(text)?);
1413
format::extract_root_table(uri, value)
1514
}
16-
17-
fn from_gura_value(uri: Option<&String>, value: GuraType) -> Value {
18-
let vk = match value {
19-
GuraType::String(value) => ValueKind::String(value),
20-
21-
GuraType::Integer(value) => ValueKind::I64(value as i64),
22-
GuraType::BigInteger(value) => ValueKind::I128(value),
23-
GuraType::Float(value) => ValueKind::Float(value),
24-
25-
GuraType::Bool(value) => ValueKind::Boolean(value),
26-
27-
GuraType::Object(table) => {
28-
let m = table
29-
.into_iter()
30-
.map(|(k, v)| (k, from_gura_value(uri, v)))
31-
.collect();
32-
33-
ValueKind::Table(m)
34-
}
35-
36-
GuraType::Array(array) => {
37-
let l = array
38-
.into_iter()
39-
.map(|v| from_gura_value(uri, v))
40-
.collect();
41-
42-
ValueKind::Array(l)
43-
}
44-
45-
GuraType::Null => ValueKind::Nil,
46-
47-
// Remaining types (only intended for internal use):
48-
_ => ValueKind::Nil,
49-
};
50-
51-
Value::new(uri, vk)
52-
}

src/file/format/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum FileFormat {
5959
#[cfg(feature = "json5")]
6060
Json5,
6161

62-
/// GURA (parsed with gura)
62+
/// GURA (parsed with serde_gura)
6363
#[cfg(feature = "gura")]
6464
Gura,
6565
}

tests/Settings-enum-test.ura

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# comment
22

3-
bar: "bar is a lowercase param"
3+
bar: "bar is a lowercase param"

tests/Settings.ura

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ place:
1717
email: "jsmith@localhost"
1818

1919
FOO: "FOO should be overridden"
20-
bar: "I am bar"
20+
bar: "I am bar"

0 commit comments

Comments
 (0)