From 6b17a3cb0614c426a037b6c97d646c3c0c524ce7 Mon Sep 17 00:00:00 2001 From: nick Date: Tue, 9 Jul 2024 16:41:31 -0400 Subject: [PATCH] Moved thread pool initialisation to Args::post_process --- src/args.rs | 10 ++++++---- src/main.rs | 11 ----------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/args.rs b/src/args.rs index c8d859b..8660ef2 100644 --- a/src/args.rs +++ b/src/args.rs @@ -1,5 +1,6 @@ use clap::{Parser, ArgAction}; use glob::Pattern; +use rayon::ThreadPoolBuilder; use crate::unit::Unit; @@ -150,6 +151,11 @@ impl Args { self.path = vec![ ".".to_owned() ]; } + ThreadPoolBuilder::new() + .num_threads(self.threads) + .build_global() + .expect("Failed to initialise threadpool"); + self } @@ -195,10 +201,6 @@ impl Args { pub const fn quiet(&self) -> bool { self.quiet } - - pub const fn threads(&self) -> usize { - self.threads - } pub fn paths(&self) -> Iter<'_, String> { self.path.iter() diff --git a/src/main.rs b/src/main.rs index bfe89fd..fa838ab 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,23 +8,12 @@ use clap::Parser; use args::Args; use directory::Directory; -use rayon::ThreadPoolBuilder; use std::process::ExitCode; fn main() -> ExitCode { let args = Args::parse().post_process(); - match ThreadPoolBuilder::new().num_threads(args.threads()).build_global() { - Ok(()) => (), - Err(e) => { - if !args.minimal() && !args.quiet() { - eprintln!("hb: {e}"); - } - return ExitCode::FAILURE; - } - }; - let mut total = 0; for path in args.paths() { let dir_structure = match Directory::new(path, &args) {