use jwalk::Parallelism;
use std::num::NonZeroUsize;
use std::path::PathBuf;
#[derive(clap::Parser)]
pub struct Args {
#[arg(long, short = 't')]
pub threads: Option<NonZeroUsize>,
pub root: Option<PathBuf>,
}
impl Args {
pub fn threads(&self) -> usize {
self.threads
.unwrap_or_else(|| {
if cfg!(target_vendor = "apple") {
NonZeroUsize::new(4).unwrap()
} else {
std::thread::available_parallelism().unwrap_or(NonZeroUsize::new(1).unwrap())
}
})
.get()
}
pub fn parallelism(&self) -> Parallelism {
match self.threads() {
1 => Parallelism::Serial,
n => Parallelism::RayonNewPool(n),
}
}
}