unc_cli_rs/types/
json.rs

1use color_eyre::eyre::WrapErr;
2use serde_json::Value;
3
4#[derive(Debug, Clone, derive_more::FromStr)]
5pub struct Json {
6    inner: Value,
7}
8
9impl From<Json> for Value {
10    fn from(item: Json) -> Self {
11        item.inner
12    }
13}
14
15impl std::fmt::Display for Json {
16    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17        self.inner.fmt(f)
18    }
19}
20
21impl interactive_clap::ToCli for Json {
22    type CliVariant = Json;
23}
24
25impl Json {
26    pub fn try_into_bytes(&self) -> color_eyre::Result<Vec<u8>> {
27        serde_json::to_vec(&self.inner).wrap_err("Data not in JSON format!")
28    }
29}