harmont_cli/output/
json.rs1use std::fmt;
6use std::io::Write;
7
8use hm_plugin_protocol::BuildEvent;
9
10use crate::runner::OutputRenderer;
11
12#[derive(Debug)]
15pub struct JsonRenderer<W> {
16 out: W,
17}
18
19impl<W> JsonRenderer<W> {
20 #[must_use]
22 pub const fn new(out: W) -> Self {
23 Self { out }
24 }
25}
26
27impl<W> OutputRenderer for JsonRenderer<W>
28where
29 W: Write + Send + fmt::Debug,
30{
31 fn on_event(&mut self, event: &BuildEvent) {
32 if let Ok(mut bytes) = serde_json::to_vec(event) {
33 bytes.push(b'\n');
34 let _ = self.out.write_all(&bytes);
35 }
36 }
37}