parallel_disk_usage/
json_data.rs

1pub mod binary_version;
2pub mod schema_version;
3
4pub use binary_version::BinaryVersion;
5pub use schema_version::SchemaVersion;
6
7use crate::{
8    data_tree::Reflection,
9    size::{Blocks, Bytes},
10};
11use derive_more::{From, TryInto};
12
13#[cfg(feature = "json")]
14use serde::{Deserialize, Serialize};
15
16/// The `"unit"` field and the `"tree"` field of [`JsonData`].
17#[derive(Debug, Clone, From, TryInto)]
18#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
19#[cfg_attr(feature = "json", serde(tag = "unit", content = "tree"))]
20#[cfg_attr(feature = "json", serde(rename_all = "kebab-case"))]
21pub enum UnitAndTree {
22    /// Tree where size is [bytes](Bytes).
23    Bytes(Reflection<String, Bytes>),
24    /// Tree where size is [blocks](Blocks).
25    Blocks(Reflection<String, Blocks>),
26}
27
28/// Output of the program with `--json-output` flag as well as
29/// input of the program with `--json-input` flag.
30#[derive(Debug, Clone)]
31#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
32#[cfg_attr(feature = "json", serde(rename_all = "kebab-case"))]
33pub struct JsonData {
34    /// The `"schema-version"` field.
35    pub schema_version: SchemaVersion,
36    /// The `"pdu"` field.
37    #[cfg_attr(feature = "json", serde(rename = "pdu"))]
38    pub binary_version: Option<BinaryVersion>,
39    /// The `"unit"` field and the `"tree"` field.
40    #[cfg_attr(feature = "json", serde(flatten))]
41    pub unit_and_tree: UnitAndTree,
42}