| 23 | } |
| 24 | |
| 25 | pub fn write_json<T: Serialize>(&mut self, data: &T) -> Result<()> { |
| 26 | match self.format { |
| 27 | OutputFormat::Json => { |
| 28 | let json = serde_json::to_string_pretty(data)?; |
| 29 | writeln!(self.writer, "{}", json)?; |
| 30 | } |
| 31 | OutputFormat::Raw | OutputFormat::Jsonl => { |
| 32 | let json = serde_json::to_string(data)?; |
| 33 | writeln!(self.writer, "{}", json)?; |
| 34 | } |
| 35 | OutputFormat::Table => { |
| 36 | let json = serde_json::to_string_pretty(data)?; |
| 37 | writeln!(self.writer, "{}", json)?; |
| 38 | } |
| 39 | } |
| 40 | Ok(()) |
| 41 | } |
| 42 | |
| 43 | pub fn write_table(&mut self, table: Table) -> Result<()> { |
| 44 | writeln!(self.writer, "{}", table)?; |