Moved thread pool initialisation to Args::post_process

main
nick 2024-07-09 16:41:31 -04:00
parent d1e027e00c
commit 6b17a3cb06
2 changed files with 6 additions and 15 deletions

View File

@ -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()

View File

@ -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) {