qlty_cloud/format/
json_each.rs

1use super::Formatter;
2use serde::Serialize;
3use std::io::Write;
4
5#[derive(Debug)]
6pub struct JsonEachRowFormatter<T: Serialize> {
7    data: Vec<T>, // Assuming data is a collection of rows
8}
9
10impl<T: Serialize + 'static> JsonEachRowFormatter<T> {
11    pub fn new(data: Vec<T>) -> Box<dyn Formatter> {
12        Box::new(Self { data })
13    }
14}
15
16impl<T: Serialize> Formatter for JsonEachRowFormatter<T> {
17    fn write_to(&self, writer: &mut dyn Write) -> anyhow::Result<()> {
18        for row in &self.data {
19            let json_row = serde_json::to_string(&row)?;
20            writer.write_all(json_row.as_bytes())?;
21            writer.write_all(b"\n")?;
22        }
23        Ok(())
24    }
25}