From 22c2387eb2e30ad35fb93d44f72ce3a7ec0d6410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moritz=20B=C3=B6hme?= Date: Fri, 3 Oct 2025 11:11:00 +0200 Subject: [PATCH] refactor: remove some clones and follow clippy --- src/main.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/main.rs b/src/main.rs index 31ce77e..2361b40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,40 +16,35 @@ async fn get_feed(url: String, client: &Client) -> Result { } fn get_domain(item: &rss::Item) -> Option { - item.link().map(|link| { - Url::parse(link) - .ok() - .map(|parsed| parsed.domain().map(|domain| domain.to_string())) - }).flatten()? + item.link() + .and_then(|link| Url::parse(link).ok()) + .and_then(|parsed| parsed.domain().map(|domain| domain.to_string())) } async fn complete(channel: Channel, client: &Client) -> Result> { let grouped: Vec> = channel .items() - .into_iter() - .chunk_by(|item| get_domain(*item)) + .iter() + .chunk_by(|item| get_domain(item)) .into_iter() .map(|(_k, v)| v.cloned().collect()) .collect(); let mut set = JoinSet::new(); - for items in grouped.into_iter() { + for mut items in grouped.into_iter() { let client = client.clone(); set.spawn(async move { - let mut new_items = vec![]; let mut wait_time = Duration::from_secs(0); - for item in items { + for item in &mut items { tokio::time::sleep(wait_time).await; - let mut new_item: rss::Item = item.clone().to_owned(); - if let Some(link) = item.link() { - if let Ok(content) = get_content(link, &client.clone()).await { - new_item.set_description(content); - }; - }; - new_items.push(new_item); + if let Some(ref link) = item.link + && let Ok(content) = get_content(link, &client.clone()).await + { + item.set_description(content); + } wait_time = Duration::from_secs(1); } - new_items + items }); }