Make --threads usize with a default value

This commit is contained in:
Valentine Briese 2023-10-15 11:04:22 -07:00
parent 00e7d792b9
commit d138a1f233
3 changed files with 10 additions and 11 deletions

View file

@ -98,9 +98,9 @@ pub struct Archive {
#[arg(short, long, default_value_t = false)]
pub(crate) yes: bool,
#[arg(help = "Override the number of threads used to download")]
#[arg(short, long)]
pub(crate) threads: Option<usize>,
#[arg(help = "The number of threads used to download")]
#[arg(short, long, default_value_t = num_cpus::get())]
pub(crate) threads: usize,
#[arg(help = "Crunchyroll series url(s)")]
#[arg(required = true)]

View file

@ -80,9 +80,9 @@ pub struct Download {
#[arg(long, default_value_t = false)]
pub(crate) force_hardsub: bool,
#[arg(help = "Override the number of threads used to download")]
#[arg(short, long)]
pub(crate) threads: Option<usize>,
#[arg(help = "The number of threads used to download")]
#[arg(short, long, default_value_t = num_cpus::get())]
pub(crate) threads: usize,
#[arg(help = "Url(s) to Crunchyroll episodes or series")]
#[arg(required = true)]

View file

@ -50,7 +50,7 @@ pub struct DownloadBuilder {
audio_sort: Option<Vec<Locale>>,
subtitle_sort: Option<Vec<Locale>>,
force_hardsub: bool,
threads: Option<usize>,
threads: usize,
}
impl DownloadBuilder {
@ -62,7 +62,7 @@ impl DownloadBuilder {
audio_sort: None,
subtitle_sort: None,
force_hardsub: false,
threads: None,
threads: num_cpus::get(),
}
}
@ -102,7 +102,7 @@ pub struct Downloader {
subtitle_sort: Option<Vec<Locale>>,
force_hardsub: bool,
threads: Option<usize>,
threads: usize,
formats: Vec<DownloadFormat>,
}
@ -575,8 +575,7 @@ impl Downloader {
None
};
// If `threads` is specified, use that many CPU cores(?).
let cpus = self.threads.unwrap_or(num_cpus::get());
let cpus = self.threads;
let mut segs: Vec<Vec<VariantSegment>> = Vec::with_capacity(cpus);
for _ in 0..cpus {
segs.push(vec![])