diff options
-rw-r--r-- | src/main.rs | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/main.rs b/src/main.rs index 8727003..53a1301 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,14 +5,20 @@ use std::{ }; use clap::Parser; -use color_eyre::eyre::{bail, eyre, Context, Result}; +use color_eyre::{ + eyre::{bail, eyre, Context, Result}, + Report, +}; use hittekaart::{ gpx::{self, Compression}, renderer, }; use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; use is_terminal::IsTerminal; -use rayon::ThreadPoolBuilder; +use rayon::{ + iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}, + ThreadPoolBuilder, +}; #[derive(Parser, Debug, Clone)] #[command(author, version, about)] @@ -69,13 +75,17 @@ fn main() -> Result<()> { bar.set_prefix("Reading GPX files"); let mut tracks = Vec::new(); - for file in &args.files { - let compression = Compression::suggest_from_path(file) - .ok_or_else(|| eyre!("Could not determine format for {file:?}"))?; - let data = gpx::extract_from_file(file, compression)?; - tracks.push(data); - bar.inc(1); - } + args.files + .par_iter() + .map(|file| { + let compression = Compression::suggest_from_path(file) + .ok_or_else(|| eyre!("Could not determine format for {file:?}"))?; + let data = gpx::extract_from_file(file, compression)?; + bar.inc(1); + Ok::<_, Report>(data) + }) + .collect_into_vec(&mut tracks); + let tracks = tracks.into_iter().collect::<Result<Vec<_>>>()?; bar.finish(); ensure_output_directory(&args.output_directory)?; |