Skip to content

Commit efe960e

Browse files
CopilotKSXGitHub
andcommitted
feat(api)!: use bon to convert structs into builder functions
Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
1 parent 6851de2 commit efe960e

6 files changed

Lines changed: 66 additions & 17 deletions

File tree

Cargo.lock

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ cli-completions = ["cli"]
5050

5151
[dependencies]
5252
assert-cmp = "0.3.0"
53+
bon = "3.9.0"
5354
clap = { version = "4.5.46", optional = true }
5455
clap_complete = { version = "4.5.57", optional = true }
5556
clap-utilities = { version = "0.2.0", optional = true }

src/app/sub.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ use crate::{
1212
status_board::GLOBAL_STATUS_BOARD,
1313
visualizer::{BarAlignment, ColumnWidthDistribution, Direction, Visualizer},
1414
};
15+
use bon::Builder;
1516
use pipe_trait::Pipe;
1617
use serde::Serialize;
1718
use std::{io::stdout, iter::once, path::PathBuf};
1819

1920
/// The sub program of the main application.
21+
#[derive(Builder)]
2022
pub struct Sub<Size, SizeGetter, HardlinksHandler, Report>
2123
where
2224
Report: ParallelReporter<Size> + Sync,

src/fs_tree_builder.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use super::{
77
size,
88
tree_builder::{Info, TreeBuilder},
99
};
10+
use bon::Builder;
1011
use pipe_trait::Pipe;
1112
use std::{
1213
fs::{read_dir, symlink_metadata},
@@ -27,16 +28,17 @@ use std::{
2728
/// size::Bytes,
2829
/// hardlink::HardlinkIgnorant,
2930
/// };
30-
/// let builder = FsTreeBuilder {
31-
/// root: std::env::current_dir().unwrap(),
32-
/// hardlinks_recorder: &HardlinkIgnorant,
33-
/// size_getter: GetApparentSize,
34-
/// reporter: &ErrorOnlyReporter::new(ErrorReport::SILENT),
35-
/// max_depth: 10,
36-
/// };
31+
/// let reporter = ErrorOnlyReporter::new(ErrorReport::SILENT);
32+
/// let builder = FsTreeBuilder::builder()
33+
/// .root(std::env::current_dir().unwrap())
34+
/// .hardlinks_recorder(&HardlinkIgnorant)
35+
/// .size_getter(GetApparentSize)
36+
/// .reporter(&reporter)
37+
/// .max_depth(10)
38+
/// .build();
3739
/// let data_tree: DataTree<OsStringDisplay, Bytes> = builder.into();
3840
/// ```
39-
#[derive(Debug)]
41+
#[derive(Debug, Builder)]
4042
pub struct FsTreeBuilder<'a, Size, SizeGetter, HardlinksRecorder, Report>
4143
where
4244
Report: Reporter<Size> + Sync + ?Sized,

src/tree_builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ pub mod info;
33
pub use info::Info;
44

55
use super::{data_tree::DataTree, size};
6+
use bon::Builder;
67
use rayon::prelude::*;
78

89
/// Collection of functions and starting points in order to build a [`DataTree`] with [`From`] or [`Into`].
9-
#[derive(Debug)]
10+
#[derive(Debug, Builder)]
1011
pub struct TreeBuilder<Path, Name, Size, GetInfo, JoinPath>
1112
where
1213
Path: Send + Sync,

src/visualizer.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub use proportion_bar::{ProportionBar, ProportionBarBlock};
1515
pub use tree::{TreeHorizontalSlice, TreeSkeletalComponent};
1616

1717
use super::{data_tree::DataTree, size};
18+
use bon::Builder;
1819
use std::fmt::Display;
1920

2021
/// Visualize a [`DataTree`].
@@ -32,17 +33,17 @@ use std::fmt::Display;
3233
/// # use parallel_disk_usage::visualizer::{Visualizer, Direction, BarAlignment, ColumnWidthDistribution};
3334
/// # fn _wrapper(create_data_tree: fn() -> DataTree<OsStringDisplay, Bytes>) {
3435
/// let data_tree: DataTree<OsStringDisplay, Bytes> = create_data_tree();
35-
/// let visualizer = Visualizer {
36-
/// data_tree: &data_tree,
37-
/// bytes_format: BytesFormat::MetricUnits,
38-
/// direction: Direction::BottomUp,
39-
/// bar_alignment: BarAlignment::Right,
40-
/// column_width_distribution: ColumnWidthDistribution::total(100),
41-
/// };
36+
/// let visualizer = Visualizer::builder()
37+
/// .data_tree(&data_tree)
38+
/// .bytes_format(BytesFormat::MetricUnits)
39+
/// .direction(Direction::BottomUp)
40+
/// .bar_alignment(BarAlignment::Right)
41+
/// .column_width_distribution(ColumnWidthDistribution::total(100))
42+
/// .build();
4243
/// println!("{visualizer}");
4344
/// # }
4445
/// ```
45-
#[derive(Debug)]
46+
#[derive(Debug, Builder)]
4647
pub struct Visualizer<'a, Name, Size>
4748
where
4849
Name: Display,

0 commit comments

Comments
 (0)