Use serde_json::to_writer for JsonEmitter::emit
Avoids an unnecessary intermediate string.
This commit is contained in:
parent
54267ddc0c
commit
00adbb2d5a
@ -148,11 +148,12 @@ impl JsonEmitter {
|
|||||||
|
|
||||||
fn emit(&mut self, val: EmitTyped<'_>) -> io::Result<()> {
|
fn emit(&mut self, val: EmitTyped<'_>) -> io::Result<()> {
|
||||||
if self.pretty {
|
if self.pretty {
|
||||||
writeln!(self.dst, "{}", serde_json::to_string_pretty(&val).unwrap())
|
serde_json::to_writer_pretty(&mut *self.dst, &val)?
|
||||||
} else {
|
} else {
|
||||||
writeln!(self.dst, "{}", serde_json::to_string(&val).unwrap())
|
serde_json::to_writer(&mut *self.dst, &val)?
|
||||||
}
|
};
|
||||||
.and_then(|_| self.dst.flush())
|
self.dst.write_all(b"\n")?;
|
||||||
|
self.dst.flush()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user