Skip to content

Commit baa1f23

Browse files
committed
feat!: rename data to size
BREAKING CHANGE: * Crate: The fields `data` and `get_data` are replaced by `size` and `size_getter` respectively. * JSON: The field `data` is replaced by `size`; `schema-version` is changed.
1 parent 182a6d7 commit baa1f23

36 files changed

+353
-354
lines changed

src/app.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
json_data::{JsonData, UnitAndTree},
99
reporter::{ErrorOnlyReporter, ErrorReport, ProgressAndErrorReporter, ProgressReport},
1010
runtime_error::RuntimeError,
11-
size::{Bytes, Size},
11+
size::{self, Bytes},
1212
visualizer::{BarAlignment, Direction, Visualizer},
1313
};
1414
use clap::Parser;
@@ -99,19 +99,19 @@ impl App {
9999
};
100100

101101
#[allow(clippy::extra_unused_type_parameters)]
102-
fn error_only_reporter<Data>(
102+
fn error_only_reporter<Size>(
103103
report_error: fn(ErrorReport),
104104
) -> ErrorOnlyReporter<fn(ErrorReport)> {
105105
ErrorOnlyReporter::new(report_error)
106106
}
107107

108-
fn progress_and_error_reporter<Data>(
108+
fn progress_and_error_reporter<Size>(
109109
report_error: fn(ErrorReport),
110-
) -> ProgressAndErrorReporter<Data, fn(ErrorReport)>
110+
) -> ProgressAndErrorReporter<Size, fn(ErrorReport)>
111111
where
112-
Data: Size + Into<u64> + Send + Sync,
113-
ProgressReport<Data>: Default + 'static,
114-
u64: Into<Data>,
112+
Size: size::Size + Into<u64> + Send + Sync,
113+
ProgressReport<Size>: Default + 'static,
114+
u64: Into<Size>,
115115
{
116116
ProgressAndErrorReporter::new(
117117
ProgressReport::TEXT,
@@ -124,8 +124,8 @@ impl App {
124124
($(
125125
$(#[$variant_attrs:meta])*
126126
{
127-
$data:ty => $format:expr;
128-
$quantity:ident => $get_data:ident;
127+
$size:ty => $format:expr;
128+
$quantity:ident => $size_getter:ident;
129129
$progress:literal => $create_reporter:ident;
130130
}
131131
)*) => { match self.args {$(
@@ -145,8 +145,8 @@ impl App {
145145
} => Sub {
146146
direction: Direction::from_top_down(top_down),
147147
bar_alignment: BarAlignment::from_align_right(align_right),
148-
get_data: $get_data,
149-
reporter: $create_reporter::<$data>(report_error),
148+
size_getter: $size_getter,
149+
reporter: $create_reporter::<$size>(report_error),
150150
bytes_format: $format(bytes_format),
151151
files,
152152
json_output,

src/app/sub.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ use crate::{
77
os_string_display::OsStringDisplay,
88
reporter::ParallelReporter,
99
runtime_error::RuntimeError,
10-
size::Size,
10+
size,
1111
status_board::GLOBAL_STATUS_BOARD,
1212
visualizer::{BarAlignment, ColumnWidthDistribution, Direction, Visualizer},
1313
};
1414
use serde::Serialize;
1515
use std::{io::stdout, iter::once, num::NonZeroUsize, path::PathBuf};
1616

1717
/// The sub program of the main application.
18-
pub struct Sub<Data, GetData, Report>
18+
pub struct Sub<Size, SizeGetter, Report>
1919
where
20-
Data: Size + Into<u64> + Serialize + Send + Sync,
21-
Report: ParallelReporter<Data> + Sync,
22-
GetData: GetSize<Size = Data> + Copy + Sync,
23-
DataTreeReflection<String, Data>: Into<UnitAndTree>,
20+
Report: ParallelReporter<Size> + Sync,
21+
Size: size::Size + Into<u64> + Serialize + Send + Sync,
22+
SizeGetter: GetSize<Size = Size> + Copy + Sync,
23+
DataTreeReflection<String, Size>: Into<UnitAndTree>,
2424
{
2525
/// List of files and/or directories.
2626
pub files: Vec<PathBuf>,
2727
/// Print JSON data instead of an ASCII chart.
2828
pub json_output: bool,
29-
/// Format to be used to [`display`](Size::display) the data.
30-
pub bytes_format: Data::DisplayFormat,
29+
/// Format to be used to [`display`](size::Size::display) the sizes returned by [`size_getter`](Self::size_getter).
30+
pub bytes_format: Size::DisplayFormat,
3131
/// The direction of the visualization.
3232
pub direction: Direction,
3333
/// The alignment of the bars.
@@ -36,8 +36,8 @@ where
3636
pub column_width_distribution: ColumnWidthDistribution,
3737
/// Maximum number of levels that should be visualized.
3838
pub max_depth: NonZeroUsize,
39-
/// Returns measured quantity of the files/directories.
40-
pub get_data: GetData,
39+
/// [Get the size](GetSize) of files/directories.
40+
pub size_getter: SizeGetter,
4141
/// Reports measurement progress.
4242
pub reporter: Report,
4343
/// Minimal size proportion required to appear.
@@ -46,12 +46,12 @@ where
4646
pub no_sort: bool,
4747
}
4848

49-
impl<Data, GetData, Report> Sub<Data, GetData, Report>
49+
impl<Size, SizeGetter, Report> Sub<Size, SizeGetter, Report>
5050
where
51-
Data: Size + Into<u64> + Serialize + Send + Sync,
52-
Report: ParallelReporter<Data> + Sync,
53-
GetData: GetSize<Size = Data> + Copy + Sync,
54-
DataTreeReflection<String, Data>: Into<UnitAndTree>,
51+
Size: size::Size + Into<u64> + Serialize + Send + Sync,
52+
Report: ParallelReporter<Size> + Sync,
53+
SizeGetter: GetSize<Size = Size> + Copy + Sync,
54+
DataTreeReflection<String, Size>: Into<UnitAndTree>,
5555
{
5656
/// Run the sub program.
5757
pub fn run(self) -> Result<(), RuntimeError> {
@@ -63,19 +63,19 @@ where
6363
bar_alignment,
6464
column_width_distribution,
6565
max_depth,
66-
get_data,
66+
size_getter,
6767
reporter,
6868
min_ratio,
6969
no_sort,
7070
} = self;
7171

7272
let mut iter = files
7373
.into_iter()
74-
.map(|root| -> DataTree<OsStringDisplay, Data> {
74+
.map(|root| -> DataTree<OsStringDisplay, Size> {
7575
FsTreeBuilder {
7676
reporter: &reporter,
7777
root,
78-
get_data,
78+
size_getter,
7979
}
8080
.into()
8181
});
@@ -98,7 +98,7 @@ where
9898
let children: Vec<_> = once(data_tree).chain(iter).collect();
9999
DataTree::dir(
100100
OsStringDisplay::os_string_from("(total)"),
101-
Data::default(),
101+
Size::default(),
102102
children,
103103
)
104104
};
@@ -114,7 +114,7 @@ where
114114
data_tree.par_cull_insignificant_data(min_ratio);
115115
}
116116
if !no_sort {
117-
data_tree.par_sort_by(|left, right| left.data().cmp(&right.data()).reverse());
117+
data_tree.par_sort_by(|left, right| left.size().cmp(&right.size()).reverse());
118118
}
119119
data_tree
120120
};

src/args.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ use text_block_macros::text_block;
5252
" Show chart in apparent sizes instead of block sizes"
5353
" $ pdu --quantity=apparent-size"
5454
""
55-
" Show data in plain numbers instead of metric units"
55+
" Show sizes in plain numbers instead of metric units"
5656
" $ pdu --bytes-format=plain"
5757
""
58-
" Show data in base 2¹⁰ units (binary) instead of base 10³ units (metric)"
58+
" Show sizes in base 2¹⁰ units (binary) instead of base 10³ units (metric)"
5959
" $ pdu --bytes-format=binary"
6060
""
6161
" Show disk usage chart of all entries regardless of size"

src/data_tree.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub use reflection::Reflection;
44

55
pub use Reflection as DataTreeReflection;
66

7-
use super::size::Size;
7+
use super::size;
88

99
/// Disk usage data of a filesystem tree.
1010
///
@@ -22,9 +22,9 @@ use super::size::Size;
2222
/// `Serialize` and `Deserialize` traits directly, instead, it can be converted into/from a
2323
/// [`Reflection`] which implements these traits.
2424
#[derive(Debug, PartialEq, Eq)]
25-
pub struct DataTree<Name, Data: Size> {
25+
pub struct DataTree<Name, Size: size::Size> {
2626
name: Name,
27-
data: Data,
27+
size: Size,
2828
children: Vec<Self>,
2929
}
3030

src/data_tree/constructors.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
use super::DataTree;
2-
use crate::size::Size;
2+
use crate::size;
33

4-
impl<Name, Data: Size> DataTree<Name, Data> {
4+
impl<Name, Size: size::Size> DataTree<Name, Size> {
55
/// Create a tree representation of a directory.
6-
pub fn dir(name: Name, inode_size: Data, children: Vec<Self>) -> Self {
7-
let data = inode_size + children.iter().map(DataTree::data).sum();
6+
pub fn dir(name: Name, inode_size: Size, children: Vec<Self>) -> Self {
7+
let size = inode_size + children.iter().map(DataTree::size).sum();
88
DataTree {
99
name,
10-
data,
10+
size,
1111
children,
1212
}
1313
}
1414

1515
/// Create a tree representation of a file.
16-
pub fn file(name: Name, data: Data) -> Self {
16+
pub fn file(name: Name, size: Size) -> Self {
1717
DataTree {
1818
name,
19-
data,
19+
size,
2020
children: Vec::with_capacity(0),
2121
}
2222
}
2323

2424
/// Create a directory constructor of fixed inode size.
25-
pub fn fixed_size_dir_constructor(inode_size: Data) -> impl Fn(Name, Vec<Self>) -> Self
25+
pub fn fixed_size_dir_constructor(inode_size: Size) -> impl Fn(Name, Vec<Self>) -> Self
2626
where
27-
Data: Copy,
27+
Size: Copy,
2828
{
2929
move |name, children| DataTree::dir(name, inode_size, children)
3030
}

src/data_tree/getters.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::DataTree;
2-
use crate::size::Size;
2+
use crate::size;
33

4-
impl<Name, Data: Size> DataTree<Name, Data> {
4+
impl<Name, Size: size::Size> DataTree<Name, Size> {
55
/// Extract name
66
pub fn name(&self) -> &Name {
77
&self.name
@@ -13,8 +13,8 @@ impl<Name, Data: Size> DataTree<Name, Data> {
1313
}
1414

1515
/// Extract total disk usage
16-
pub fn data(&self) -> Data {
17-
self.data
16+
pub fn size(&self) -> Size {
17+
self.size
1818
}
1919

2020
/// Extract children

src/data_tree/reflection.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::size::Size;
1+
use crate::size;
22
use std::{
33
collections::VecDeque,
44
ffi::OsStr,
@@ -30,11 +30,11 @@ use serde::{Deserialize, Serialize};
3030
#[derive(Debug, Clone, PartialEq, Eq)]
3131
#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
3232
#[cfg_attr(feature = "json", serde(rename_all = "kebab-case"))]
33-
pub struct Reflection<Name, Data: Size> {
33+
pub struct Reflection<Name, Size: size::Size> {
3434
/// Name of the tree.
3535
pub name: Name,
3636
/// Disk usage of a file or total disk usage of a folder.
37-
pub data: Data,
37+
pub size: Size,
3838
/// Data of children filesystem subtrees.
3939
pub children: Vec<Self>,
4040
}
@@ -43,31 +43,31 @@ pub struct Reflection<Name, Data: Size> {
4343
/// [`DataTree`](crate::data_tree::DataTree) fails.
4444
#[derive(Debug, Clone, PartialEq, Eq)]
4545
#[non_exhaustive]
46-
pub enum ConversionError<Name, Data: Size> {
47-
/// When a node's data is less than the sum of its children.
46+
pub enum ConversionError<Name, Size: size::Size> {
47+
/// When a node's size is less than the sum of its children.
4848
ExcessiveChildren {
4949
/// Path from root to the node.
5050
path: VecDeque<Name>,
51-
/// Data hold by the node.
52-
data: Data,
51+
/// Size hold by the node.
52+
size: Size,
5353
/// Children of the node.
54-
children: Vec<Reflection<Name, Data>>,
55-
/// Sum of data hold by children of the node.
56-
children_sum: Data,
54+
children: Vec<Reflection<Name, Size>>,
55+
/// Sum of size hold by children of the node.
56+
children_sum: Size,
5757
},
5858
}
5959

60-
impl<Name, Data> Display for ConversionError<Name, Data>
60+
impl<Name, Size> Display for ConversionError<Name, Size>
6161
where
6262
Name: AsRef<OsStr> + Debug,
63-
Data: Size,
63+
Size: size::Size,
6464
{
6565
fn fmt(&self, formatter: &mut Formatter<'_>) -> Result<(), Error> {
6666
use ConversionError::*;
6767
match self {
6868
ExcessiveChildren {
6969
path,
70-
data,
70+
size,
7171
children_sum,
7272
..
7373
} => {
@@ -77,10 +77,7 @@ where
7777
.fold(PathBuf::new(), |acc, x| acc.join(x));
7878
write!(
7979
formatter,
80-
"ExcessiveChildren: {path:?}: {data:?} is less than {sum:?}",
81-
path = path,
82-
data = data,
83-
sum = children_sum,
80+
"ExcessiveChildren: {path:?}: {size:?} is less than {children_sum:?}",
8481
)
8582
}
8683
}

src/data_tree/reflection/convert.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
use super::Reflection;
2-
use crate::{data_tree::DataTree, size::Size};
2+
use crate::{data_tree::DataTree, size};
33

4-
impl<Name, Data: Size> From<DataTree<Name, Data>> for Reflection<Name, Data> {
5-
fn from(source: DataTree<Name, Data>) -> Self {
4+
impl<Name, Size: size::Size> From<DataTree<Name, Size>> for Reflection<Name, Size> {
5+
fn from(source: DataTree<Name, Size>) -> Self {
66
let DataTree {
77
name,
8-
data,
8+
size,
99
children,
1010
} = source;
1111
let children: Vec<_> = children.into_iter().map(Reflection::from).collect();
1212
Reflection {
1313
name,
14-
data,
14+
size,
1515
children,
1616
}
1717
}
1818
}
1919

20-
impl<Name, Data: Size> DataTree<Name, Data> {
20+
impl<Name, Size: size::Size> DataTree<Name, Size> {
2121
/// Create reflection.
22-
pub fn into_reflection(self) -> Reflection<Name, Data> {
22+
pub fn into_reflection(self) -> Reflection<Name, Size> {
2323
self.into()
2424
}
2525
}

0 commit comments

Comments
 (0)