Skip to content

Commit c5c94eb

Browse files
committed
refactor: simplify call-site syntax of CreateReporter
1 parent 0c0f2b3 commit c5c94eb

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/app.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ impl App {
135135
) -> <<Self::SizeGetter as GetSize>::Size as size::Size>::DisplayFormat;
136136
}
137137

138+
type QuantityIndexToSizeType<const INDEX: u8> =
139+
<<() as QuantityUtils<INDEX>>::SizeGetter as GetSize>::Size;
140+
138141
impl QuantityUtils<{ quantity_index::APPARENT_SIZE }> for () {
139142
const QUANTITY: Quantity = Quantity::ApparentSize;
140143
type SizeGetter = GetApparentSize;
@@ -162,28 +165,31 @@ impl App {
162165
fn formatter(_: BytesFormat) {}
163166
}
164167

165-
trait CreateReporter<const REPORT_PROGRESS: bool, Size> {
168+
trait CreateReporter<const REPORT_PROGRESS: bool, const QUANTITY_INDEX: u8> {
166169
type Reporter;
167170
fn create_reporter(report_error: fn(ErrorReport)) -> Self::Reporter;
168171
}
169172

170-
impl<Size> CreateReporter<false, Size> for ()
173+
impl<const QUANTITY_INDEX: u8> CreateReporter<false, QUANTITY_INDEX> for ()
171174
where
172-
Size: size::Size,
175+
(): QuantityUtils<QUANTITY_INDEX>,
176+
QuantityIndexToSizeType<QUANTITY_INDEX>: size::Size,
173177
{
174178
type Reporter = ErrorOnlyReporter<fn(ErrorReport)>;
175179
fn create_reporter(report_error: fn(ErrorReport)) -> Self::Reporter {
176180
ErrorOnlyReporter::new(report_error)
177181
}
178182
}
179183

180-
impl<Size> CreateReporter<true, Size> for ()
184+
impl<const QUANTITY_INDEX: u8> CreateReporter<true, QUANTITY_INDEX> for ()
181185
where
182-
Size: size::Size + Into<u64> + Send + Sync,
183-
ProgressReport<Size>: Default + 'static,
184-
u64: Into<Size>,
186+
(): QuantityUtils<QUANTITY_INDEX>,
187+
QuantityIndexToSizeType<QUANTITY_INDEX>: size::Size + Into<u64> + Send + Sync,
188+
ProgressReport<QuantityIndexToSizeType<QUANTITY_INDEX>>: Default + 'static,
189+
u64: Into<QuantityIndexToSizeType<QUANTITY_INDEX>>,
185190
{
186-
type Reporter = ProgressAndErrorReporter<Size, fn(ErrorReport)>;
191+
type Reporter =
192+
ProgressAndErrorReporter<QuantityIndexToSizeType<QUANTITY_INDEX>, fn(ErrorReport)>;
187193
fn create_reporter(report_error: fn(ErrorReport)) -> Self::Reporter {
188194
ProgressAndErrorReporter::new(
189195
ProgressReport::TEXT,
@@ -215,7 +221,7 @@ impl App {
215221
direction: Direction::from_top_down(top_down),
216222
bar_alignment: BarAlignment::from_align_right(align_right),
217223
size_getter: <() as QuantityUtils<{ quantity_index::$quantity_index }>>::SIZE_GETTER,
218-
reporter: <() as CreateReporter<$progress, <<() as QuantityUtils<{ quantity_index::$quantity_index }>>::SizeGetter as GetSize>::Size>>::create_reporter(report_error),
224+
reporter: <() as CreateReporter<$progress, { quantity_index::$quantity_index }>>::create_reporter(report_error),
219225
bytes_format: <() as QuantityUtils<{ quantity_index::$quantity_index }>>::formatter(bytes_format),
220226
files,
221227
json_output,

0 commit comments

Comments
 (0)