1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#![allow(clippy::unit_arg)]
use serde::Serialize;
use std::io;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
#[non_exhaustive]
pub enum OutputFormat {
Human {
verbose: bool,
},
Serializable(SerializableFormat),
}
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(test, derive(proptest_derive::Arbitrary))]
#[non_exhaustive]
pub enum SerializableFormat {
Json,
JsonPretty,
}
impl SerializableFormat {
pub fn to_writer(
self,
value: &impl Serialize,
writer: impl io::Write,
) -> serde_json::Result<()> {
match self {
SerializableFormat::Json => serde_json::to_writer(writer, value),
SerializableFormat::JsonPretty => serde_json::to_writer_pretty(writer, value),
}
}
}