Skip to content

Commit

Permalink
Merge pull request #200 from sval-rs/fix/128bit-serde
Browse files Browse the repository at this point in the history
Fix support for 128bit numbers streamed via serde
  • Loading branch information
KodrAus authored Oct 15, 2024
2 parents c6a3c9f + 64bb6c5 commit f1f4991
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions nested/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
8 changes: 8 additions & 0 deletions serde/src/to_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ impl<'sval, S: sval::Stream<'sval>> serde::Serializer for Stream<S> {
self.stream_value(v)
}

fn serialize_i128(mut self, v: i128) -> Result<Self::Ok, Self::Error> {
self.stream_value(v)
}

fn serialize_u8(mut self, v: u8) -> Result<Self::Ok, Self::Error> {
self.stream_value(v)
}
Expand All @@ -163,6 +167,10 @@ impl<'sval, S: sval::Stream<'sval>> serde::Serializer for Stream<S> {
self.stream_value(v)
}

fn serialize_u128(mut self, v: u128) -> Result<Self::Ok, Self::Error> {
self.stream_value(v)
}

fn serialize_f32(mut self, v: f32) -> Result<Self::Ok, Self::Error> {
self.stream_value(v)
}
Expand Down
20 changes: 20 additions & 0 deletions serde/test/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f1f4991

Please sign in to comment.