diff --git a/src/ser.rs b/src/ser.rs index b965f0ed1..80c2deb0c 100644 --- a/src/ser.rs +++ b/src/ser.rs @@ -74,47 +74,37 @@ where #[inline] fn serialize_bool(self, value: bool) -> Result<()> { - tri!(self - .formatter + self.formatter .write_bool(&mut self.writer, value) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[inline] fn serialize_i8(self, value: i8) -> Result<()> { - tri!(self - .formatter + self.formatter .write_i8(&mut self.writer, value) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[inline] fn serialize_i16(self, value: i16) -> Result<()> { - tri!(self - .formatter + self.formatter .write_i16(&mut self.writer, value) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[inline] fn serialize_i32(self, value: i32) -> Result<()> { - tri!(self - .formatter + self.formatter .write_i32(&mut self.writer, value) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[inline] fn serialize_i64(self, value: i64) -> Result<()> { - tri!(self - .formatter + self.formatter .write_i64(&mut self.writer, value) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_i128(self, value: i128) -> Result<()> { @@ -125,38 +115,30 @@ where #[inline] fn serialize_u8(self, value: u8) -> Result<()> { - tri!(self - .formatter + self.formatter .write_u8(&mut self.writer, value) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[inline] fn serialize_u16(self, value: u16) -> Result<()> { - tri!(self - .formatter + self.formatter .write_u16(&mut self.writer, value) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[inline] fn serialize_u32(self, value: u32) -> Result<()> { - tri!(self - .formatter + self.formatter .write_u32(&mut self.writer, value) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[inline] fn serialize_u64(self, value: u64) -> Result<()> { - tri!(self - .formatter + self.formatter .write_u64(&mut self.writer, value) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_u128(self, value: u128) -> Result<()> { @@ -168,39 +150,29 @@ where #[inline] fn serialize_f32(self, value: f32) -> Result<()> { match value.classify() { - FpCategory::Nan | FpCategory::Infinite => { - tri!(self - .formatter - .write_null(&mut self.writer) - .map_err(Error::io)); - } - _ => { - tri!(self - .formatter - .write_f32(&mut self.writer, value) - .map_err(Error::io)); - } + FpCategory::Nan | FpCategory::Infinite => self + .formatter + .write_null(&mut self.writer) + .map_err(Error::io), + _ => self + .formatter + .write_f32(&mut self.writer, value) + .map_err(Error::io), } - Ok(()) } #[inline] fn serialize_f64(self, value: f64) -> Result<()> { match value.classify() { - FpCategory::Nan | FpCategory::Infinite => { - tri!(self - .formatter - .write_null(&mut self.writer) - .map_err(Error::io)); - } - _ => { - tri!(self - .formatter - .write_f64(&mut self.writer, value) - .map_err(Error::io)); - } + FpCategory::Nan | FpCategory::Infinite => self + .formatter + .write_null(&mut self.writer) + .map_err(Error::io), + _ => self + .formatter + .write_f64(&mut self.writer, value) + .map_err(Error::io), } - Ok(()) } #[inline] @@ -212,8 +184,7 @@ where #[inline] fn serialize_str(self, value: &str) -> Result<()> { - tri!(format_escaped_str(&mut self.writer, &mut self.formatter, value).map_err(Error::io)); - Ok(()) + format_escaped_str(&mut self.writer, &mut self.formatter, value).map_err(Error::io) } #[inline] @@ -228,11 +199,9 @@ where #[inline] fn serialize_unit(self) -> Result<()> { - tri!(self - .formatter + self.formatter .write_null(&mut self.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[inline] @@ -292,11 +261,9 @@ where .formatter .end_object_value(&mut self.writer) .map_err(Error::io)); - tri!(self - .formatter + self.formatter .end_object(&mut self.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[inline] @@ -485,11 +452,9 @@ where } } } - tri!(self - .formatter + self.formatter .end_string(&mut self.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } } @@ -536,11 +501,9 @@ where .map_err(Error::io)); *state = State::Rest; tri!(value.serialize(&mut **ser)); - tri!(ser - .formatter + ser.formatter .end_array_value(&mut ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[cfg(feature = "arbitrary_precision")] Compound::Number { .. } => unreachable!(), @@ -552,13 +515,10 @@ where #[inline] fn end(self) -> Result<()> { match self { - Compound::Map { ser, state } => { - match state { - State::Empty => {} - _ => tri!(ser.formatter.end_array(&mut ser.writer).map_err(Error::io)), - } - Ok(()) - } + Compound::Map { ser, state } => match state { + State::Empty => Ok(()), + _ => ser.formatter.end_array(&mut ser.writer).map_err(Error::io), + }, #[cfg(feature = "arbitrary_precision")] Compound::Number { .. } => unreachable!(), #[cfg(feature = "raw_value")] @@ -639,8 +599,7 @@ where .formatter .end_object_value(&mut ser.writer) .map_err(Error::io)); - tri!(ser.formatter.end_object(&mut ser.writer).map_err(Error::io)); - Ok(()) + ser.formatter.end_object(&mut ser.writer).map_err(Error::io) } #[cfg(feature = "arbitrary_precision")] Compound::Number { .. } => unreachable!(), @@ -673,11 +632,9 @@ where tri!(key.serialize(MapKeySerializer { ser: *ser })); - tri!(ser - .formatter + ser.formatter .end_object_key(&mut ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[cfg(feature = "arbitrary_precision")] Compound::Number { .. } => unreachable!(), @@ -698,11 +655,9 @@ where .begin_object_value(&mut ser.writer) .map_err(Error::io)); tri!(value.serialize(&mut **ser)); - tri!(ser - .formatter + ser.formatter .end_object_value(&mut ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } #[cfg(feature = "arbitrary_precision")] Compound::Number { .. } => unreachable!(), @@ -714,13 +669,10 @@ where #[inline] fn end(self) -> Result<()> { match self { - Compound::Map { ser, state } => { - match state { - State::Empty => {} - _ => tri!(ser.formatter.end_object(&mut ser.writer).map_err(Error::io)), - } - Ok(()) - } + Compound::Map { ser, state } => match state { + State::Empty => Ok(()), + _ => ser.formatter.end_object(&mut ser.writer).map_err(Error::io), + }, #[cfg(feature = "arbitrary_precision")] Compound::Number { .. } => unreachable!(), #[cfg(feature = "raw_value")] @@ -747,8 +699,7 @@ where #[cfg(feature = "arbitrary_precision")] Compound::Number { ser, .. } => { if key == crate::number::TOKEN { - tri!(value.serialize(NumberStrEmitter(ser))); - Ok(()) + value.serialize(NumberStrEmitter(ser)) } else { Err(invalid_number()) } @@ -756,8 +707,7 @@ where #[cfg(feature = "raw_value")] Compound::RawValue { ser, .. } => { if key == crate::raw::TOKEN { - tri!(value.serialize(RawValueStrEmitter(ser))); - Ok(()) + value.serialize(RawValueStrEmitter(ser)) } else { Err(invalid_raw_value()) } @@ -811,8 +761,7 @@ where .formatter .end_object_value(&mut ser.writer) .map_err(Error::io)); - tri!(ser.formatter.end_object(&mut ser.writer).map_err(Error::io)); - Ok(()) + ser.formatter.end_object(&mut ser.writer).map_err(Error::io) } #[cfg(feature = "arbitrary_precision")] Compound::Number { .. } => unreachable!(), @@ -894,12 +843,10 @@ where .formatter .write_i8(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_i16(self, value: i16) -> Result<()> { @@ -913,12 +860,10 @@ where .formatter .write_i16(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_i32(self, value: i32) -> Result<()> { @@ -932,12 +877,10 @@ where .formatter .write_i32(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_i64(self, value: i64) -> Result<()> { @@ -951,12 +894,10 @@ where .formatter .write_i64(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_i128(self, value: i128) -> Result<()> { @@ -970,12 +911,10 @@ where .formatter .write_i128(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_u8(self, value: u8) -> Result<()> { @@ -989,12 +928,10 @@ where .formatter .write_u8(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_u16(self, value: u16) -> Result<()> { @@ -1008,12 +945,10 @@ where .formatter .write_u16(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_u32(self, value: u32) -> Result<()> { @@ -1027,12 +962,10 @@ where .formatter .write_u32(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_u64(self, value: u64) -> Result<()> { @@ -1046,12 +979,10 @@ where .formatter .write_u64(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_u128(self, value: u128) -> Result<()> { @@ -1065,12 +996,10 @@ where .formatter .write_u128(&mut self.ser.writer, value) .map_err(Error::io)); - tri!(self - .ser + self.ser .formatter .end_string(&mut self.ser.writer) - .map_err(Error::io)); - Ok(()) + .map_err(Error::io) } fn serialize_f32(self, _value: f32) -> Result<()> { @@ -1990,13 +1919,8 @@ impl<'a> Formatter for PrettyFormatter<'a> { where W: ?Sized + io::Write, { - if first { - tri!(writer.write_all(b"\n")); - } else { - tri!(writer.write_all(b",\n")); - } - tri!(indent(writer, self.current_indent, self.indent)); - Ok(()) + tri!(writer.write_all(if first { b"\n" } else { b",\n" })); + indent(writer, self.current_indent, self.indent) } #[inline] @@ -2038,11 +1962,7 @@ impl<'a> Formatter for PrettyFormatter<'a> { where W: ?Sized + io::Write, { - if first { - tri!(writer.write_all(b"\n")); - } else { - tri!(writer.write_all(b",\n")); - } + tri!(writer.write_all(if first { b"\n" } else { b",\n" })); indent(writer, self.current_indent, self.indent) } @@ -2071,8 +1991,7 @@ where { tri!(formatter.begin_string(writer)); tri!(format_escaped_str_contents(writer, formatter, value)); - tri!(formatter.end_string(writer)); - Ok(()) + formatter.end_string(writer) } fn format_escaped_str_contents( @@ -2104,11 +2023,11 @@ where start = i + 1; } - if start != bytes.len() { - tri!(formatter.write_string_fragment(writer, &value[start..])); + if start == bytes.len() { + return Ok(()); } - Ok(()) + formatter.write_string_fragment(writer, &value[start..]) } const BB: u8 = b'b'; // \x08 @@ -2157,8 +2076,7 @@ where T: ?Sized + Serialize, { let mut ser = Serializer::new(writer); - tri!(value.serialize(&mut ser)); - Ok(()) + value.serialize(&mut ser) } /// Serialize the given data structure as pretty-printed JSON into the IO @@ -2176,8 +2094,7 @@ where T: ?Sized + Serialize, { let mut ser = Serializer::pretty(writer); - tri!(value.serialize(&mut ser)); - Ok(()) + value.serialize(&mut ser) } /// Serialize the given data structure as a JSON byte vector.