From cb7005a2dd3d36060ba8cf8f01680dad89454f89 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sun, 6 Aug 2023 01:39:02 +0500 Subject: [PATCH] Add support for i128 / u128 Because MSRV is 1.56 which has support of 128-bit integers, serde_if_integer128 hack is not needed --- src/de.rs | 2 ++ src/ser.rs | 10 ++++++++++ src/token.rs | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/de.rs b/src/de.rs index a5d9e1d..71e0a61 100644 --- a/src/de.rs +++ b/src/de.rs @@ -118,10 +118,12 @@ impl<'de, 'a> de::Deserializer<'de> for &'a mut Deserializer<'de> { Token::I16(v) => visitor.visit_i16(v), Token::I32(v) => visitor.visit_i32(v), Token::I64(v) => visitor.visit_i64(v), + Token::I128(v) => visitor.visit_i128(v), Token::U8(v) => visitor.visit_u8(v), Token::U16(v) => visitor.visit_u16(v), Token::U32(v) => visitor.visit_u32(v), Token::U64(v) => visitor.visit_u64(v), + Token::U128(v) => visitor.visit_u128(v), Token::F32(v) => visitor.visit_f32(v), Token::F64(v) => visitor.visit_f64(v), Token::Char(v) => visitor.visit_char(v), diff --git a/src/ser.rs b/src/ser.rs index 245bbe8..7134739 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -109,6 +109,11 @@ impl<'s, 'a> ser::Serializer for &'s mut Serializer<'a> { Ok(()) } + fn serialize_i128(self, v: i128) -> Result<(), Error> { + assert_next_token!(self, I128(v)); + Ok(()) + } + fn serialize_u8(self, v: u8) -> Result<(), Error> { assert_next_token!(self, U8(v)); Ok(()) @@ -129,6 +134,11 @@ impl<'s, 'a> ser::Serializer for &'s mut Serializer<'a> { Ok(()) } + fn serialize_u128(self, v: u128) -> Result<(), Error> { + assert_next_token!(self, U128(v)); + Ok(()) + } + fn serialize_f32(self, v: f32) -> Result<(), Error> { assert_next_token!(self, F32(v)); Ok(()) diff --git a/src/token.rs b/src/token.rs index 03b3b7b..d1ce306 100644 --- a/src/token.rs +++ b/src/token.rs @@ -47,6 +47,15 @@ pub enum Token { /// ``` I64(i64), + /// A serialized `i128`. + /// + /// ``` + /// # use serde_test::{assert_tokens, Token}; + /// # + /// assert_tokens(&0i128, &[Token::I128(0)]); + /// ``` + I128(i128), + /// A serialized `u8`. /// /// ``` @@ -83,6 +92,15 @@ pub enum Token { /// ``` U64(u64), + /// A serialized `u128`. + /// + /// ``` + /// # use serde_test::{assert_tokens, Token}; + /// # + /// assert_tokens(&0u128, &[Token::U128(0)]); + /// ``` + U128(u128), + /// A serialized `f32`. /// /// ```