From 9026cc8d426107f140f029a1a9a73da53beb2e1a Mon Sep 17 00:00:00 2001 From: BlackDex Date: Mon, 4 Feb 2019 17:27:40 +0100 Subject: [PATCH] Fixed issue when the iconlist is smaller then 5 When the iconlist was smaller then 5 items, it would cause a panic. Solved by using .truncate() on the iconlist. --- src/api/icons.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/api/icons.rs b/src/api/icons.rs index fcfbe7df..cb3669cd 100644 --- a/src/api/icons.rs +++ b/src/api/icons.rs @@ -265,7 +265,7 @@ fn get_icon_priority(href: &str, sizes: &str) -> u8 { /// /// # Arguments /// * `sizes` - The size of the icon if available as a x value like 32x32. -/// +/// /// # Example /// ``` /// let (width, height) = parse_sizes("64x64"); // (64, 64) @@ -296,9 +296,9 @@ fn download_icon(domain: &str) -> Result, Error> { let mut buffer = Vec::new(); - let mut attempts = 0; - while attempts < 5 { - let url = &iconlist.remove(0).href; + iconlist.truncate(5); + for icon in iconlist { + let url = icon.href; info!("Downloading icon for {} via {}...", domain, url); match get_page_with_cookies(&url, &cookie_str) { Ok(mut res) => { @@ -308,7 +308,6 @@ fn download_icon(domain: &str) -> Result, Error> { }, Err(_) => info!("Download failed for {}", url), }; - attempts += 1; } if buffer.is_empty() {