Skip to content

Commit

Permalink
Update try!() macros to new ? syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarmathe committed Feb 1, 2021
1 parent e7c2a35 commit 52cc3f0
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,20 @@ impl Drain for Streamer3164 {
let mut buf = buf.borrow_mut();
let res = {
|| {
try!(self.format.format(&mut *buf, info, logger_values));
self.format.format(&mut *buf, info, logger_values)?;
let sever = level_to_severity(info.level());
{
let io = try!(
let io =
self.io
.lock()
.map_err(|_| Error::new(ErrorKind::Other, "locking error"))
);
.map_err(|_| Error::new(ErrorKind::Other, "locking error"))?;

let buf = String::from_utf8_lossy(&buf);
let buf = io.format_3164(sever, &buf).into_bytes();

let mut pos = 0;
while pos < buf.len() {
let n = try!(io.send_raw(&buf[pos..]));
let n = io.send_raw(&buf[pos..])?;
if n == 0 {
break;
}
Expand Down Expand Up @@ -137,12 +136,12 @@ impl Format3164 {
record: &Record,
logger_kv: &OwnedKVList,
) -> io::Result<()> {
try!(write!(io, "{}", record.msg()));
write!(io, "{}", record.msg())?;

let mut ser = KSV::new(io);
{
try!(logger_kv.serialize(record, &mut ser));
try!(record.kv().serialize(record, &mut ser));
logger_kv.serialize(record, &mut ser)?;
record.kv().serialize(record, &mut ser)?;
}
Ok(())
}
Expand All @@ -161,7 +160,7 @@ impl<W: io::Write> KSV<W> {

impl<W: io::Write> slog::Serializer for KSV<W> {
fn emit_arguments(&mut self, key: &str, val: &fmt::Arguments) -> slog::Result {
try!(write!(self.io, ", {}: {}", key, val));
write!(self.io, ", {}: {}", key, val)?;
Ok(())
}
}
Expand Down

0 comments on commit 52cc3f0

Please sign in to comment.