Skip to content

Commit

Permalink
Add support for i128 / u128
Browse files Browse the repository at this point in the history
Because MSRV is 1.56 which has support of 128-bit integers, serde_if_integer128 hack is not needed
  • Loading branch information
Mingun committed Aug 6, 2024
1 parent bbb18e2 commit cb7005a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
10 changes: 10 additions & 0 deletions src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -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(())
Expand Down
18 changes: 18 additions & 0 deletions src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
/// ```
Expand Down Expand Up @@ -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`.
///
/// ```
Expand Down

0 comments on commit cb7005a

Please sign in to comment.