Moved thread pool initialisation to Args::post_process
parent
d1e027e00c
commit
6b17a3cb06
10
src/args.rs
10
src/args.rs
|
@ -1,5 +1,6 @@
|
||||||
use clap::{Parser, ArgAction};
|
use clap::{Parser, ArgAction};
|
||||||
use glob::Pattern;
|
use glob::Pattern;
|
||||||
|
use rayon::ThreadPoolBuilder;
|
||||||
|
|
||||||
use crate::unit::Unit;
|
use crate::unit::Unit;
|
||||||
|
|
||||||
|
@ -150,6 +151,11 @@ impl Args {
|
||||||
self.path = vec![ ".".to_owned() ];
|
self.path = vec![ ".".to_owned() ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThreadPoolBuilder::new()
|
||||||
|
.num_threads(self.threads)
|
||||||
|
.build_global()
|
||||||
|
.expect("Failed to initialise threadpool");
|
||||||
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,10 +202,6 @@ impl Args {
|
||||||
self.quiet
|
self.quiet
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const fn threads(&self) -> usize {
|
|
||||||
self.threads
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn paths(&self) -> Iter<'_, String> {
|
pub fn paths(&self) -> Iter<'_, String> {
|
||||||
self.path.iter()
|
self.path.iter()
|
||||||
}
|
}
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -8,23 +8,12 @@ use clap::Parser;
|
||||||
|
|
||||||
use args::Args;
|
use args::Args;
|
||||||
use directory::Directory;
|
use directory::Directory;
|
||||||
use rayon::ThreadPoolBuilder;
|
|
||||||
|
|
||||||
use std::process::ExitCode;
|
use std::process::ExitCode;
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
fn main() -> ExitCode {
|
||||||
let args = Args::parse().post_process();
|
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;
|
let mut total = 0;
|
||||||
for path in args.paths() {
|
for path in args.paths() {
|
||||||
let dir_structure = match Directory::new(path, &args) {
|
let dir_structure = match Directory::new(path, &args) {
|
||||||
|
|
Loading…
Reference in New Issue