From 64bb6c52db1990f38f8e8df5df884578811ae017 Mon Sep 17 00:00:00 2001 From: Ashley Mannix Date: Wed, 16 Oct 2024 00:55:22 +1000 Subject: [PATCH] fix support for 128bit numbers streamed via serde --- nested/Cargo.toml | 3 +++ serde/src/to_value.rs | 8 ++++++++ serde/test/lib.rs | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/nested/Cargo.toml b/nested/Cargo.toml index 3ebce46e..5ef99111 100644 --- a/nested/Cargo.toml +++ b/nested/Cargo.toml @@ -14,6 +14,9 @@ categories = ["encoding", "no-std"] [package.metadata.docs.rs] features = ["std"] +[lints.rust] +unexpected_cfgs = { level = "allow", check-cfg = ['cfg(no_debug_assertions)'] } + [features] default = ["alloc"] std = ["alloc", "sval/std", "sval_buffer/std"] diff --git a/serde/src/to_value.rs b/serde/src/to_value.rs index be259438..6415980b 100644 --- a/serde/src/to_value.rs +++ b/serde/src/to_value.rs @@ -147,6 +147,10 @@ impl<'sval, S: sval::Stream<'sval>> serde::Serializer for Stream { self.stream_value(v) } + fn serialize_i128(mut self, v: i128) -> Result { + self.stream_value(v) + } + fn serialize_u8(mut self, v: u8) -> Result { self.stream_value(v) } @@ -163,6 +167,10 @@ impl<'sval, S: sval::Stream<'sval>> serde::Serializer for Stream { self.stream_value(v) } + fn serialize_u128(mut self, v: u128) -> Result { + self.stream_value(v) + } + fn serialize_f32(mut self, v: f32) -> Result { self.stream_value(v) } diff --git a/serde/test/lib.rs b/serde/test/lib.rs index 4ba9389d..3e771444 100644 --- a/serde/test/lib.rs +++ b/serde/test/lib.rs @@ -141,6 +141,26 @@ fn option_none_to_serialize() { ) } +#[test] +fn u128_to_serialize() { + // NOTE: Can't check the `serde` end of this because `serde_test` + // lacks 128bit number support + let v = 42u128; + + let sval = &{ + use sval_test::Token::*; + + [U128(42)] + }; + + assert_tokens(&sval_serde::ToValue::new(&v), sval); + + assert_tokens( + &sval_serde::ToValue::new(sval_serde::ToSerialize::new(&v)), + sval, + ); +} + #[test] fn map_to_serialize() { test_case(