bard/render/
json.rs

1use std::fs::File;
2
3use super::{Render, RenderContext};
4use crate::app::App;
5use crate::prelude::*;
6
7#[derive(Debug, Default)]
8pub struct RJson;
9
10impl RJson {
11    pub fn new() -> Self {
12        Self
13    }
14}
15
16impl Render for RJson {
17    fn render(&self, _app: &App, output: &Path, context: RenderContext) -> Result<()> {
18        File::create(output)
19            .map_err(Error::from)
20            .and_then(|mut f| serde_json::to_writer_pretty(&mut f, &context).map_err(Error::from))
21            .with_context(|| format!("Error writing output file: {:?}", output))
22    }
23}