Skip to content

Commit 85960f8

Browse files
committed
feat(api)!: rename UnitAndTree to JsonDataBody
1 parent 840d182 commit 85960f8

5 files changed

Lines changed: 23 additions & 23 deletions

File tree

src/app.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
bytes_format::BytesFormat,
88
get_size::{GetApparentSize, GetSize},
99
hook,
10-
json_data::{JsonData, UnitAndTree},
10+
json_data::{JsonData, JsonDataBody},
1111
reporter::{ErrorOnlyReporter, ErrorReport, ProgressAndErrorReporter, ProgressReport},
1212
runtime_error::RuntimeError,
1313
size,
@@ -64,10 +64,10 @@ impl App {
6464
let direction = Direction::from_top_down(top_down);
6565
let bar_alignment = BarAlignment::from_align_right(align_right);
6666

67-
let unit_and_tree = stdin()
67+
let body = stdin()
6868
.pipe(serde_json::from_reader::<_, JsonData>)
6969
.map_err(RuntimeError::DeserializationFailure)?
70-
.unit_and_tree;
70+
.body;
7171

7272
macro_rules! visualize {
7373
($reflection:expr, $bytes_format: expr) => {{
@@ -85,9 +85,9 @@ impl App {
8585
}};
8686
}
8787

88-
let visualization = match unit_and_tree {
89-
UnitAndTree::Bytes(tree) => visualize!(tree.tree, bytes_format),
90-
UnitAndTree::Blocks(tree) => visualize!(tree.tree, ()),
88+
let visualization = match body {
89+
JsonDataBody::Bytes(tree) => visualize!(tree.tree, bytes_format),
90+
JsonDataBody::Blocks(tree) => visualize!(tree.tree, ()),
9191
};
9292

9393
print!("{visualization}"); // it already ends with "\n", println! isn't needed here.

src/app/sub.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
get_size::GetSize,
66
hardlink::HardlinkListReflection,
77
hook,
8-
json_data::{BinaryVersion, JsonData, JsonTree, SchemaVersion, UnitAndTree},
8+
json_data::{BinaryVersion, JsonData, JsonDataBody, JsonTree, SchemaVersion},
99
os_string_display::OsStringDisplay,
1010
reporter::ParallelReporter,
1111
runtime_error::RuntimeError,
@@ -24,7 +24,7 @@ where
2424
Size: size::Size + Into<u64> + Serialize + Send + Sync,
2525
SizeGetter: GetSize<Size = Size> + Copy + Sync,
2626
Hook: hook::Hook<Size, Report> + DeduplicateHardlinkSizes<Size> + Copy + Sync,
27-
JsonTree<Size>: Into<UnitAndTree>,
27+
JsonTree<Size>: Into<JsonDataBody>,
2828
{
2929
/// List of files and/or directories.
3030
pub files: Vec<PathBuf>,
@@ -60,7 +60,7 @@ where
6060
Report: ParallelReporter<Size> + Sync,
6161
SizeGetter: GetSize<Size = Size> + Copy + Sync,
6262
Hook: hook::Hook<Size, Report> + DeduplicateHardlinkSizes<Size> + Copy + Sync,
63-
JsonTree<Size>: Into<UnitAndTree>,
63+
JsonTree<Size>: Into<JsonDataBody>,
6464
{
6565
/// Run the sub program.
6666
pub fn run(self) -> Result<(), RuntimeError> {
@@ -154,7 +154,7 @@ where
154154
let json_data = JsonData {
155155
schema_version: SchemaVersion,
156156
binary_version: Some(BinaryVersion::current()),
157-
unit_and_tree: json_tree.into(),
157+
body: json_tree.into(),
158158
};
159159
return serde_json::to_writer(stdout(), &json_data)
160160
.map_err(RuntimeError::SerializationFailure);

src/json_data.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use derive_more::{Deref, DerefMut, From, TryInto};
1414
#[cfg(feature = "json")]
1515
use serde::{Deserialize, Serialize};
1616

17-
/// The `"tree"` field of [`JsonData`].
17+
/// The `"tree"` field and the `"shared-inodes"` field of [`JsonData`].
1818
#[derive(Debug, Clone, Deref, DerefMut)]
1919
#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
2020
#[cfg_attr(feature = "json", serde(rename_all = "kebab-case"))]
@@ -28,12 +28,12 @@ pub struct JsonTree<Size: size::Size> {
2828
pub shared_inodes: Option<HardlinkListReflection<Size>>,
2929
}
3030

31-
/// The `"unit"` field and the `"tree"` field of [`JsonData`].
31+
/// The `"unit"` field, the `"tree"` field, and the `"shared-inodes"` field of [`JsonData`].
3232
#[derive(Debug, Clone, From, TryInto)]
3333
#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
3434
#[cfg_attr(feature = "json", serde(tag = "unit"))]
3535
#[cfg_attr(feature = "json", serde(rename_all = "kebab-case"))]
36-
pub enum UnitAndTree {
36+
pub enum JsonDataBody {
3737
/// Tree where size is [bytes](Bytes).
3838
Bytes(JsonTree<Bytes>),
3939
/// Tree where size is [blocks](Blocks).
@@ -51,7 +51,7 @@ pub struct JsonData {
5151
/// The `"pdu"` field.
5252
#[cfg_attr(feature = "json", serde(rename = "pdu"))]
5353
pub binary_version: Option<BinaryVersion>,
54-
/// The `"unit"` field and the `"tree"` field.
54+
/// The `"unit"` field, the `"tree"` field, and the `"shared-inodes"` field.
5555
#[cfg_attr(feature = "json", serde(flatten))]
56-
pub unit_and_tree: UnitAndTree,
56+
pub body: JsonDataBody,
5757
}

tests/deduplicate_hardlinks.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub use _utils::*;
77
use command_extra::CommandExtra;
88
use parallel_disk_usage::{
99
data_tree::Reflection,
10-
json_data::{JsonData, UnitAndTree},
10+
json_data::{JsonData, JsonDataBody},
1111
size::Bytes,
1212
};
1313
use pipe_trait::Pipe;
@@ -42,8 +42,8 @@ fn deduplicate_multiple_hardlinks_to_a_single_file() {
4242
.pipe_as_ref(serde_json::from_str::<JsonData>)
4343
.expect("parse stdout as JsonData");
4444

45-
let UnitAndTree::Bytes(tree) = &json.unit_and_tree else {
46-
panic!("expecting Bytes but got {:?}", &json.unit_and_tree);
45+
let JsonDataBody::Bytes(tree) = &json.body else {
46+
panic!("expecting Bytes but got {:?}", &json.body);
4747
};
4848

4949
let file_size = workspace
@@ -96,9 +96,9 @@ fn do_not_deduplicate_multiple_hardlinks_to_a_single_file() {
9696
.pipe_as_ref(serde_json::from_str::<JsonData>)
9797
.expect("parse stdout as JsonData");
9898

99-
let actual_size = match &json.unit_and_tree {
100-
UnitAndTree::Blocks(_) => panic!("expecting Bytes, but got {:?}", &json.unit_and_tree),
101-
UnitAndTree::Bytes(tree) => tree.size,
99+
let actual_size = match &json.body {
100+
JsonDataBody::Blocks(_) => panic!("expecting Bytes, but got {:?}", &json.body),
101+
JsonDataBody::Bytes(tree) => tree.size,
102102
};
103103

104104
let expected_size = workspace

tests/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn json_output() {
7474
.pipe(stdout_text)
7575
.pipe_as_ref(serde_json::from_str::<JsonData>)
7676
.expect("parse stdout as JsonData")
77-
.unit_and_tree
77+
.body
7878
.pipe(TryInto::<SampleJsonTree>::try_into)
7979
.expect("extract reflection")
8080
.tree
@@ -106,7 +106,7 @@ fn json_input() {
106106
let json_data = JsonData {
107107
schema_version: SchemaVersion,
108108
binary_version: None,
109-
unit_and_tree: json_tree.into(),
109+
body: json_tree.into(),
110110
};
111111
let json = serde_json::to_string_pretty(&json_data).expect("convert sample tree to JSON");
112112
eprintln!("JSON: {json}\n");

0 commit comments

Comments
 (0)