From 25344aa613b415117b3dc6951cbdac0dbb692ab9 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Mon, 30 Oct 2017 13:15:44 +0200 Subject: [PATCH] Applied clippy suggestions. --- hammond-data/src/dbcheckup.rs | 7 ++++--- hammond-data/src/feedparser.rs | 4 ++-- hammond-gtk/src/main.rs | 2 +- hammond-gtk/src/widgets/podcast.rs | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/hammond-data/src/dbcheckup.rs b/hammond-data/src/dbcheckup.rs index 57f7e0a..235d0aa 100644 --- a/hammond-data/src/dbcheckup.rs +++ b/hammond-data/src/dbcheckup.rs @@ -8,6 +8,7 @@ use chrono::prelude::*; use std::path::Path; use std::fs; +use std::sync::Arc; // TODO: Write unit test. fn download_checker(db: &Database) -> Result<()> { @@ -19,7 +20,7 @@ fn download_checker(db: &Database) -> Result<()> { episodes.par_iter_mut().for_each(|ep| { if !Path::new(ep.local_uri().unwrap()).exists() { ep.set_local_uri(None); - let res = ep.save(&db.clone()); + let res = ep.save(&Arc::clone(db)); if let Err(err) = res { error!("Error while trying to update episode: {:#?}", ep); error!("Error: {}", err); @@ -40,11 +41,11 @@ fn watched_cleaner(db: &Database) -> Result<()> { let now_utc = Utc::now().timestamp() as i32; episodes.par_iter_mut().for_each(|mut ep| { if ep.local_uri().is_some() && ep.watched().is_some() { - let watched = ep.watched().unwrap().clone(); + let watched = ep.watched().unwrap(); // TODO: expose a config and a user set option. let limit = watched + 172_800; // add 2days in seconds if now_utc > limit { - let e = delete_local_content(&db.clone(), &mut ep); + let e = delete_local_content(&Arc::clone(db), &mut ep); if let Err(err) = e { error!("Error while trying to delete file: {:?}", ep.local_uri()); error!("Error: {}", err); diff --git a/hammond-data/src/feedparser.rs b/hammond-data/src/feedparser.rs index 586cd5c..d983eef 100644 --- a/hammond-data/src/feedparser.rs +++ b/hammond-data/src/feedparser.rs @@ -6,7 +6,7 @@ use models; // TODO: look into how bad-utf8 is handled in rss crate, // and figure if there is a need for checking before parsing. // TODO: Extend the support for parsing itunes extensions -/// Parses a rss::Channel into a NewPodcast Struct. +/// Parses a `rss::Channel` into a `NewPodcast` Struct. pub fn parse_podcast(chan: &Channel, source_id: i32) -> models::NewPodcast { let title = chan.title().trim().to_owned(); let link = chan.link().trim().to_owned(); @@ -30,7 +30,7 @@ pub fn parse_podcast(chan: &Channel, source_id: i32) -> models::NewPodcast { } } -/// Parses a rss::Item into a NewEpisode Struct. +/// Parses an `rss::Item` into a `NewEpisode` Struct. pub fn parse_episode(item: &Item, parent_id: i32) -> models::NewEpisode { let title = item.title().map(|s| s.trim()); let description = item.description().map(|s| s.trim()); diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 61123d2..4c98a68 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -61,7 +61,7 @@ fn build_ui(app: >k::Application) { }); app.add_action(&quit); - let db2 = db.clone(); + let db2 = Arc::clone(&db); let check = gio::SimpleAction::new("check", None); check.connect_activate(move |_, _| { let _ = dbcheckup::run(&db2); diff --git a/hammond-gtk/src/widgets/podcast.rs b/hammond-gtk/src/widgets/podcast.rs index 74ba8cf..54eb58b 100644 --- a/hammond-gtk/src/widgets/podcast.rs +++ b/hammond-gtk/src/widgets/podcast.rs @@ -111,10 +111,10 @@ pub fn podcast_widget( if let Some(t) = title { let tempdb = db.lock().unwrap(); - let parent = dbqueries::load_podcast_from_title(&tempdb, &t).unwrap(); + let parent = dbqueries::load_podcast_from_title(&tempdb, t).unwrap(); let f = dbqueries::get_pd_unplayed_episodes(&tempdb, &parent); if let Ok(l) = f { - if l.len() > 0 { + if !l.is_empty() { played_button.show() } }