Skip to content

Commit

Permalink
chore: Upgrade to ron to 0.9
Browse files Browse the repository at this point in the history
- Ron `0.9` refactored the `Number` value variant to be lossless,
  which requires more thorough matching.
  - 128 integer support in Ron requires feature opt-in via `Cargo.toml`,
    (_as `ValueKind` implements an equivalent type, `config-rs` could opt-in_).
- Ron `0.9` also introduces a new `Bytes` value variant to support
  rusty byte strings (`Vec<u8>`). This was to resolve a roundtrip
  serialization bug with base64 strings when serde `deserialize_any` is used
  (_which lacks a type hint and would deserialize as a literal string to bytes,
  instead of base64 decoded string to bytes_).
- Clarified that the option value variant dereferences a boxed ron value.

Signed-off-by: Brennan Kinney <5098581+polarathene@users.noreply.github.com>
  • Loading branch information
polarathene committed Oct 17, 2023
1 parent 55c464e commit 57d8690
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ toml = { version = "0.8", optional = true }
serde_json = { version = "1.0.2", optional = true }
yaml-rust = { version = "0.4", optional = true }
rust-ini = { version = "0.19", optional = true }
ron = { version = "0.8", optional = true }
ron = { version = "0.9", optional = true }
json5_rs = { version = "0.4", optional = true, package = "json5" }
indexmap = { version = "2.0.0", features = ["serde"], optional = true }
convert_case = { version = "0.6", optional = true }
Expand Down
17 changes: 14 additions & 3 deletions src/file/format/ron.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ fn from_ron_value(
value: ron::Value,
) -> Result<Value, Box<dyn Error + Send + Sync>> {
let kind = match value {
// Option<Boxed<ron::Value>> requires deref of boxed value
ron::Value::Option(value) => match value {
Some(value) => from_ron_value(uri, *value)?.kind,
Some(boxed) => from_ron_value(uri, *boxed)?.kind,
None => ValueKind::Nil,
},

Expand All @@ -27,10 +28,20 @@ fn from_ron_value(
ron::Value::Bool(value) => ValueKind::Boolean(value),

ron::Value::Number(value) => match value {
ron::Number::Float(value) => ValueKind::Float(value.get()),
ron::Number::Integer(value) => ValueKind::I64(value),
ron::Number::F32(value) => ValueKind::Float(value.get() as f64),
ron::Number::F64(value) => ValueKind::Float(value.get()),
ron::Number::I8(value) => ValueKind::I64(value.into()),
ron::Number::I16(value) => ValueKind::I64(value.into()),
ron::Number::I32(value) => ValueKind::I64(value.into()),
ron::Number::I64(value) => ValueKind::I64(value),
ron::Number::U8(value) => ValueKind::U64(value.into()),
ron::Number::U16(value) => ValueKind::U64(value.into()),
ron::Number::U32(value) => ValueKind::U64(value.into()),
ron::Number::U64(value) => ValueKind::U64(value),
},

ron::Value::Bytes(_) => todo!(),

ron::Value::Char(value) => ValueKind::String(value.to_string()),

ron::Value::String(value) => ValueKind::String(value),
Expand Down

0 comments on commit 57d8690

Please sign in to comment.