Skip to content

Commit

Permalink
Merge pull request 940 from Lucretiel/int128
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 19, 2022
2 parents 4217e8e + 84d6d95 commit 486598b
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions src/ser.rs
Expand Up @@ -121,7 +121,7 @@ where
serde_if_integer128! {
fn serialize_i128(self, value: i128) -> Result<()> {
self.formatter
.write_number_str(&mut self.writer, &value.to_string())
.write_i128(&mut self.writer, value)
.map_err(Error::io)
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ where
serde_if_integer128! {
fn serialize_u128(self, value: u128) -> Result<()> {
self.formatter
.write_number_str(&mut self.writer, &value.to_string())
.write_u128(&mut self.writer, value)
.map_err(Error::io)
}
}
Expand Down Expand Up @@ -974,7 +974,7 @@ where
tri!(self
.ser
.formatter
.write_number_str(&mut self.ser.writer, &value.to_string())
.write_i128(&mut self.ser.writer, value)
.map_err(Error::io));
tri!(self
.ser
Expand Down Expand Up @@ -1071,7 +1071,7 @@ where
tri!(self
.ser
.formatter
.write_number_str(&mut self.ser.writer, &value.to_string())
.write_u128(&mut self.ser.writer, value)
.map_err(Error::io));
tri!(self
.ser
Expand Down Expand Up @@ -1661,6 +1661,17 @@ pub trait Formatter {
writer.write_all(s.as_bytes())
}

/// Writes an integer value like `-123` to the specified writer.
#[inline]
fn write_i128<W>(&mut self, writer: &mut W, value: i128) -> io::Result<()>
where
W: ?Sized + io::Write,
{
let mut buffer = itoa::Buffer::new();
let s = buffer.format(value);
writer.write_all(s.as_bytes())
}

/// Writes an integer value like `123` to the specified writer.
#[inline]
fn write_u8<W>(&mut self, writer: &mut W, value: u8) -> io::Result<()>
Expand Down Expand Up @@ -1705,6 +1716,17 @@ pub trait Formatter {
writer.write_all(s.as_bytes())
}

/// Writes an integer value like `123` to the specified writer.
#[inline]
fn write_u128<W>(&mut self, writer: &mut W, value: u128) -> io::Result<()>
where
W: ?Sized + io::Write,
{
let mut buffer = itoa::Buffer::new();
let s = buffer.format(value);
writer.write_all(s.as_bytes())
}

/// Writes a floating point value like `-31.26e+12` to the specified writer.
#[inline]
fn write_f32<W>(&mut self, writer: &mut W, value: f32) -> io::Result<()>
Expand Down

0 comments on commit 486598b

Please sign in to comment.