qlty_cloud/format/
json.rs1use super::Formatter;
2use serde::Serialize;
3use std::io::Write;
4
5#[derive(Debug)]
6pub struct JsonFormatter<T: Serialize> {
7 data: T,
8}
9
10impl<T: Serialize + 'static> JsonFormatter<T> {
11 pub fn new(data: T) -> Box<dyn Formatter> {
12 Box::new(Self { data })
13 }
14}
15
16impl<T: Serialize> Formatter for JsonFormatter<T> {
17 fn write_to(&self, writer: &mut dyn Write) -> anyhow::Result<()> {
18 let json = serde_json::to_string_pretty(&self.data)?;
19 writer.write_all(json.as_bytes())?;
20 writer.write_all(b"\n")?;
21 Ok(())
22 }
23}