From c3ece41d81bfdfb3b0883a6d0de578b7487fc1be Mon Sep 17 00:00:00 2001 From: Teascade Date: Mon, 24 Aug 2020 20:37:36 +0300 Subject: [PATCH] make some neatness changes --- src/api.rs | 8 ++------ src/main.rs | 32 +++++++++++++++----------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/api.rs b/src/api.rs index 758509d..2afad21 100644 --- a/src/api.rs +++ b/src/api.rs @@ -209,9 +209,7 @@ impl API { } else { while awaiting > 0 { if let Ok((loc, rec)) = i_receiver.try_recv() { - if API::add_error_back(loc, &rec, &mut locations) { - println!("Sent back to queue"); - } + API::add_error_back(loc, &rec, &mut locations); awaiting -= 1; sender.send(rec).ok(); } @@ -222,9 +220,7 @@ impl API { } } else { if let Ok((loc, rec)) = i_receiver.try_recv() { - if API::add_error_back(loc, &rec, &mut locations) { - println!("Sent back to queue"); - } + API::add_error_back(loc, &rec, &mut locations); awaiting -= 1; sender.send(rec).ok(); } diff --git a/src/main.rs b/src/main.rs index 810089a..a31fe03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,25 +118,23 @@ fn run( loop { match receiver.try_recv() { Ok(res) => match res { - Ok(loc) => { - if loc.is_ok() { + Ok(loc) => match loc { + Ok(mut loc) => { counter += 1; + let remaining = exp_time(&api, states.len() as u64 - counter as u64); + print!( + "Done: {:<5.2}% Remaining: {:<5.2} seconds\r", + counter as f32 / states.len() as f32 * 100., + remaining.as_secs_f32() + ); + std::io::stdout().lock().flush().ok(); + locations.append(&mut loc); } - let remaining = exp_time(&api, states.len() as u64 - counter as u64); - print!( - "Done: {:<5.2}% Remaining: {:<5.2} seconds\r", - counter as f32 / states.len() as f32 * 100., - remaining.as_secs_f32() - ); - std::io::stdout().lock().flush().ok(); - match loc { - Ok(mut loc) => locations.append(&mut loc), - Err(e) => eprintln!( - "Error fetching location data: {}", - e.message.unwrap_or(String::new()) - ), - } - } + Err(e) => eprintln!( + "Error fetching location data: {}", + e.message.unwrap_or(String::new()) + ), + }, Err(e) => eprintln!("{}", e), }, Err(e) => {