use crate::formatter::Formatter;
use crate::layer::Tree;
use std::io::{self, Write};
#[derive(Clone, Copy)]
pub struct Json<const IS_COMPACT: bool> {
_priv: (),
}
impl Json<true> {
pub const fn compact() -> Self {
Json { _priv: () }
}
}
impl Formatter for Json<true> {
fn fmt(&self, tree: Tree, mut writer: &mut Vec<u8>) -> io::Result<()> {
serde_json::to_writer(&mut writer, &tree)?;
writeln!(writer)
}
}
impl Json<false> {
pub const fn pretty() -> Self {
Json { _priv: () }
}
}
impl Formatter for Json<false> {
fn fmt(&self, tree: Tree, mut writer: &mut Vec<u8>) -> io::Result<()> {
serde_json::to_writer_pretty(&mut writer, &tree)?;
writeln!(writer)
}
}