Skip to content
Snippets Groups Projects
Commit ed7c7b5c authored by Taiki Endo's avatar Taiki Endo Committed by Sean McArthur
Browse files

Replace try! macro with ? operator

parent 09772c4e
No related branches found
No related tags found
No related merge requests found
...@@ -14,27 +14,27 @@ pub struct BsDebug<'a>(pub &'a [u8]); ...@@ -14,27 +14,27 @@ pub struct BsDebug<'a>(pub &'a [u8]);
impl<'a> fmt::Debug for BsDebug<'a> { impl<'a> fmt::Debug for BsDebug<'a> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
try!(write!(fmt, "b\"")); write!(fmt, "b\"")?;
for &c in self.0 { for &c in self.0 {
// https://doc.rust-lang.org/reference.html#byte-escapes // https://doc.rust-lang.org/reference.html#byte-escapes
if c == b'\n' { if c == b'\n' {
try!(write!(fmt, "\\n")); write!(fmt, "\\n")?;
} else if c == b'\r' { } else if c == b'\r' {
try!(write!(fmt, "\\r")); write!(fmt, "\\r")?;
} else if c == b'\t' { } else if c == b'\t' {
try!(write!(fmt, "\\t")); write!(fmt, "\\t")?;
} else if c == b'\\' || c == b'"' { } else if c == b'\\' || c == b'"' {
try!(write!(fmt, "\\{}", c as char)); write!(fmt, "\\{}", c as char)?;
} else if c == b'\0' { } else if c == b'\0' {
try!(write!(fmt, "\\0")); write!(fmt, "\\0")?;
// ASCII printable // ASCII printable
} else if c >= 0x20 && c < 0x7f { } else if c >= 0x20 && c < 0x7f {
try!(write!(fmt, "{}", c as char)); write!(fmt, "{}", c as char)?;
} else { } else {
try!(write!(fmt, "\\x{:02x}", c)); write!(fmt, "\\x{:02x}", c)?;
} }
} }
try!(write!(fmt, "\"")); write!(fmt, "\"")?;
Ok(()) Ok(())
} }
} }
...@@ -31,7 +31,7 @@ macro_rules! serde_impl { ...@@ -31,7 +31,7 @@ macro_rules! serde_impl {
let len = cmp::min(seq.size_hint().unwrap_or(0), 4096); let len = cmp::min(seq.size_hint().unwrap_or(0), 4096);
let mut values = Vec::with_capacity(len); let mut values = Vec::with_capacity(len);
while let Some(value) = try!(seq.next_element()) { while let Some(value) = seq.next_element()? {
values.push(value); values.push(value);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment