From 57d8690b7bb9303433f3f9706fa879acd9f35638 Mon Sep 17 00:00:00 2001 From: polarathene <5098581+polarathene@users.noreply.github.com> Date: Tue, 17 Oct 2023 15:00:15 +1300 Subject: [PATCH] chore: Upgrade to `ron` to `0.9` - 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`). 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> --- Cargo.toml | 2 +- src/file/format/ron.rs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8b08f5be..5422cc5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/file/format/ron.rs b/src/file/format/ron.rs index 9ac81a9d..732aca90 100644 --- a/src/file/format/ron.rs +++ b/src/file/format/ron.rs @@ -17,8 +17,9 @@ fn from_ron_value( value: ron::Value, ) -> Result> { let kind = match value { + // Option> 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, }, @@ -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),