diff options
author | Nick Hackman <snickhackman@gmail.com> | 2019-08-20 12:59:28 -0400 |
---|---|---|
committer | Nick Hackman <snickhackman@gmail.com> | 2019-08-20 12:59:28 -0400 |
commit | 022e914ccf9ae0ed61e5fd09152b41f37737602a (patch) | |
tree | 2b79e4c97e1d8885b0c6209be702f4a17bd09333 | |
parent | d55ec1b4c1a8313b00f1abd95beaf10a9a5bc1a9 (diff) | |
download | milf-rs-022e914ccf9ae0ed61e5fd09152b41f37737602a.tar.gz milf-rs-022e914ccf9ae0ed61e5fd09152b41f37737602a.zip |
Propogate write! errors to ser::Error
std::fmt::Errors are now converted to ser::Errors via ser::Error::custom
-rw-r--r-- | src/ser.rs | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -25,8 +25,6 @@ //! # fn main() {} //! ``` -#![allow(unused_must_use)] - use std::cell::Cell; use std::error; use std::fmt::{self, Write}; @@ -424,7 +422,7 @@ impl<'a> Serializer<'a> { fn display<T: fmt::Display>(&mut self, t: T, type_: &'static str) -> Result<(), Error> { self.emit_key(type_)?; - write!(self.dst, "{}", t); + write!(self.dst, "{}", t).map_err(ser::Error::custom)?; if let State::Table { .. } = self.state { self.dst.push_str("\n"); } @@ -517,7 +515,7 @@ impl<'a> Serializer<'a> { _ => false, }); if ok { - write!(self.dst, "{}", key); + write!(self.dst, "{}", key).map_err(ser::Error::custom)?; } else { self.emit_str(key, true)?; } @@ -650,7 +648,7 @@ impl<'a> Serializer<'a> { '\u{22}' => self.dst.push_str("\\\""), '\u{5c}' => self.dst.push_str("\\\\"), c if c < '\u{1f}' => { - write!(self.dst, "\\u{:04X}", ch as u32); + write!(self.dst, "\\u{:04X}", ch as u32).map_err(ser::Error::custom)?; } ch => self.dst.push(ch), } @@ -754,15 +752,15 @@ macro_rules! serialize_float { ($this:expr, $v:expr) => {{ $this.emit_key("float")?; if ($v.is_nan() || $v == 0.0) && $v.is_sign_negative() { - write!($this.dst, "-"); + write!($this.dst, "-").map_err(ser::Error::custom)?; } if $v.is_nan() { - write!($this.dst, "nan"); + write!($this.dst, "nan").map_err(ser::Error::custom)?; } else { - write!($this.dst, "{}", $v); + write!($this.dst, "{}", $v).map_err(ser::Error::custom)?; } if $v % 1.0 == 0.0 { - write!($this.dst, ".0"); + write!($this.dst, ".0").map_err(ser::Error::custom)?; } if let State::Table { .. } = $this.state { $this.dst.push_str("\n"); |