Skip to content

Commit aa6ac6a

Browse files
committed
feat(api)!: rename UnitAndTree to JsonDataBody
1 parent 694129b commit aa6ac6a

4 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/app.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
args::{Args, Quantity, Threads},
77
bytes_format::BytesFormat,
88
get_size::{GetApparentSize, GetSize},
9-
json_data::{JsonData, UnitAndTree},
9+
json_data::{JsonData, JsonDataBody},
1010
reporter::{ErrorOnlyReporter, ErrorReport, ProgressAndErrorReporter, ProgressReport},
1111
runtime_error::RuntimeError,
1212
size,
@@ -60,10 +60,10 @@ impl App {
6060
let direction = Direction::from_top_down(top_down);
6161
let bar_alignment = BarAlignment::from_align_right(align_right);
6262

63-
let unit_and_tree = stdin()
63+
let body = stdin()
6464
.pipe(serde_json::from_reader::<_, JsonData>)
6565
.map_err(RuntimeError::DeserializationFailure)?
66-
.unit_and_tree;
66+
.body;
6767

6868
macro_rules! visualize {
6969
($reflection:expr, $bytes_format: expr) => {{
@@ -81,9 +81,9 @@ impl App {
8181
}};
8282
}
8383

84-
let visualization = match unit_and_tree {
85-
UnitAndTree::Bytes(reflection) => visualize!(reflection, bytes_format),
86-
UnitAndTree::Blocks(reflection) => visualize!(reflection, ()),
84+
let visualization = match body {
85+
JsonDataBody::Bytes(reflection) => visualize!(reflection, bytes_format),
86+
JsonDataBody::Blocks(reflection) => visualize!(reflection, ()),
8787
};
8888

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

src/app/sub.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
data_tree::{DataTree, DataTreeReflection},
44
fs_tree_builder::FsTreeBuilder,
55
get_size::GetSize,
6-
json_data::{BinaryVersion, JsonData, SchemaVersion, UnitAndTree},
6+
json_data::{BinaryVersion, JsonData, JsonDataBody, SchemaVersion},
77
os_string_display::OsStringDisplay,
88
reporter::ParallelReporter,
99
runtime_error::RuntimeError,
@@ -20,7 +20,7 @@ where
2020
Report: ParallelReporter<Size> + Sync,
2121
Size: size::Size + Into<u64> + Serialize + Send + Sync,
2222
SizeGetter: GetSize<Size = Size> + Copy + Sync,
23-
DataTreeReflection<String, Size>: Into<UnitAndTree>,
23+
DataTreeReflection<String, Size>: Into<JsonDataBody>,
2424
{
2525
/// List of files and/or directories.
2626
pub files: Vec<PathBuf>,
@@ -51,7 +51,7 @@ where
5151
Size: size::Size + Into<u64> + Serialize + Send + Sync,
5252
Report: ParallelReporter<Size> + Sync,
5353
SizeGetter: GetSize<Size = Size> + Copy + Sync,
54-
DataTreeReflection<String, Size>: Into<UnitAndTree>,
54+
DataTreeReflection<String, Size>: Into<JsonDataBody>,
5555
{
5656
/// Run the sub program.
5757
pub fn run(self) -> Result<(), RuntimeError> {
@@ -126,15 +126,15 @@ where
126126
GLOBAL_STATUS_BOARD.clear_line(0);
127127

128128
if json_output {
129-
let unit_and_tree: UnitAndTree = data_tree
129+
let body: JsonDataBody = data_tree
130130
.into_reflection() // I really want to use std::mem::transmute here but can't.
131131
.par_convert_names_to_utf8() // TODO: allow non-UTF8 somehow.
132132
.expect("convert all names from raw string to UTF-8")
133133
.into();
134134
let json_data = JsonData {
135135
schema_version: SchemaVersion,
136136
binary_version: Some(BinaryVersion::current()),
137-
unit_and_tree,
137+
body,
138138
};
139139
return serde_json::to_writer(stdout(), &json_data)
140140
.map_err(RuntimeError::SerializationFailure);

src/json_data.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use serde::{Deserialize, Serialize};
1818
#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
1919
#[cfg_attr(feature = "json", serde(tag = "unit", content = "tree"))]
2020
#[cfg_attr(feature = "json", serde(rename_all = "kebab-case"))]
21-
pub enum UnitAndTree {
21+
pub enum JsonDataBody {
2222
/// Tree where size is [bytes](Bytes).
2323
Bytes(Reflection<String, Bytes>),
2424
/// Tree where size is [blocks](Blocks).
@@ -38,5 +38,5 @@ pub struct JsonData {
3838
pub binary_version: Option<BinaryVersion>,
3939
/// The `"unit"` field and the `"tree"` field.
4040
#[cfg_attr(feature = "json", serde(flatten))]
41-
pub unit_and_tree: UnitAndTree,
41+
pub body: JsonDataBody,
4242
}

tests/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ fn json_output() {
7373
.pipe(stdout_text)
7474
.pipe_as_ref(serde_json::from_str::<JsonData>)
7575
.expect("parse stdout as JsonData")
76-
.unit_and_tree
76+
.body
7777
.pipe(TryInto::<SampleReflection>::try_into)
7878
.expect("extract reflection")
7979
.pipe(sanitize_tree_reflection);
@@ -99,7 +99,7 @@ fn json_input() {
9999
let json_data = JsonData {
100100
schema_version: SchemaVersion,
101101
binary_version: None,
102-
unit_and_tree: sample_tree().into_reflection().into(),
102+
body: sample_tree().into_reflection().into(),
103103
};
104104
let json = serde_json::to_string_pretty(&json_data).expect("convert sample tree to JSON");
105105
eprintln!("JSON: {json}\n");

0 commit comments

Comments
 (0)