Skip to content

Commit

Permalink
Add ability to cache i128/u128 during serialization
Browse files Browse the repository at this point in the history
`Content` size doesn't changed, because it is already big enough
(64 bytes due to `TupleVariant` and `StructVariant`).

Fixes (2):
    newtype::i128             (serialize)
    newtype::u128             (serialize)

failures (6):
    newtype::enum_::newtype   (deserialize)
    newtype::enum_:;struct    (deserialize)
    newtype::enum_::tuple     (deserialize)
    newtype::newtype_struct   (deserialize)
    newtype::struct_          (deserialize)
    struct_                   (deserialize)
  • Loading branch information
Mingun committed Oct 21, 2024
1 parent fe55512 commit adf5a3f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions serde/src/private/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ where
Err(self.bad_type(Unsupported::Integer))
}

fn serialize_i128(self, _: i128) -> Result<Self::Ok, Self::Error> {
Err(self.bad_type(Unsupported::Integer))
}

fn serialize_u128(self, _: u128) -> Result<Self::Ok, Self::Error> {
Err(self.bad_type(Unsupported::Integer))
}

fn serialize_f32(self, _: f32) -> Result<Self::Ok, Self::Error> {
Err(self.bad_type(Unsupported::Float))
}
Expand Down Expand Up @@ -424,11 +432,13 @@ mod content {
U16(u16),
U32(u32),
U64(u64),
U128(u128),

I8(i8),
I16(i16),
I32(i32),
I64(i64),
I128(i128),

F32(f32),
F64(f64),
Expand Down Expand Up @@ -471,10 +481,12 @@ mod content {
Content::U16(u) => serializer.serialize_u16(u),
Content::U32(u) => serializer.serialize_u32(u),
Content::U64(u) => serializer.serialize_u64(u),
Content::U128(i) => serializer.serialize_u128(i),
Content::I8(i) => serializer.serialize_i8(i),
Content::I16(i) => serializer.serialize_i16(i),
Content::I32(i) => serializer.serialize_i32(i),
Content::I64(i) => serializer.serialize_i64(i),
Content::I128(i) => serializer.serialize_i128(i),
Content::F32(f) => serializer.serialize_f32(f),
Content::F64(f) => serializer.serialize_f64(f),
Content::Char(c) => serializer.serialize_char(c),
Expand Down Expand Up @@ -603,6 +615,14 @@ mod content {
Ok(Content::U64(v))
}

fn serialize_i128(self, v: i128) -> Result<Content, E> {
Ok(Content::I128(v))
}

fn serialize_u128(self, v: u128) -> Result<Content, E> {
Ok(Content::U128(v))
}

fn serialize_f32(self, v: f32) -> Result<Content, E> {
Ok(Content::F32(v))
}
Expand Down Expand Up @@ -1052,6 +1072,14 @@ where
Err(Self::bad_type(Unsupported::Integer))
}

fn serialize_i128(self, _: i128) -> Result<Self::Ok, Self::Error> {
Err(Self::bad_type(Unsupported::Integer))
}

fn serialize_u128(self, _: u128) -> Result<Self::Ok, Self::Error> {
Err(Self::bad_type(Unsupported::Integer))
}

fn serialize_f32(self, _: f32) -> Result<Self::Ok, Self::Error> {
Err(Self::bad_type(Unsupported::Float))
}
Expand Down

0 comments on commit adf5a3f

Please sign in to comment.