Applied some clippy suggestions.

This commit is contained in:
Jordan Petridis
2017-10-09 16:49:00 +03:00
parent 2c1b55c2fb
commit f1d3cd5e25
6 changed files with 21 additions and 18 deletions
+2
View File
@@ -1,3 +1,5 @@
#![cfg_attr(feature = "cargo-clippy", allow(let_and_return))]
use diesel::prelude::*;
use models::{Episode, Podcast, Source};
+1 -1
View File
@@ -20,7 +20,7 @@ pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result<models::NewPodcas
Ok(foo)
}
pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result<models::NewEpisode<'a>> {
pub fn parse_episode(item: &Item, parent_id: i32) -> Result<models::NewEpisode> {
let title = item.title();
let description = item.description();
let guid = item.guid().map(|x| x.value());
+10 -9
View File
@@ -1,4 +1,5 @@
#![allow(dead_code)]
#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr))]
use diesel::prelude::*;
use diesel;
@@ -39,7 +40,7 @@ fn index_podcast(con: &SqliteConnection, pd: &NewPodcast) -> Result<()> {
}
fn index_episode(con: &SqliteConnection, ep: &NewEpisode) -> Result<()> {
match dbqueries::load_episode(con, &ep.uri.unwrap()) {
match dbqueries::load_episode(con, ep.uri.unwrap()) {
Ok(mut foo) => if foo.title() != ep.title
|| foo.published_date() != ep.published_date.as_ref().map(|x| x.as_str())
{
@@ -74,7 +75,7 @@ fn insert_return_podcast(con: &SqliteConnection, pd: &NewPodcast) -> Result<Podc
fn insert_return_episode(con: &SqliteConnection, ep: &NewEpisode) -> Result<Episode> {
index_episode(con, ep)?;
Ok(dbqueries::load_episode(con, &ep.uri.unwrap())?)
Ok(dbqueries::load_episode(con, ep.uri.unwrap())?)
}
pub fn index_loop(db: SqliteConnection, force: bool) -> Result<()> {
@@ -105,18 +106,18 @@ fn complete_index_from_source(
req.read_to_string(&mut buf)?;
let chan = rss::Channel::from_str(&buf)?;
complete_index(mutex, chan, &source)?;
complete_index(mutex, &chan, source)?;
Ok(())
}
fn complete_index(
mutex: Arc<Mutex<SqliteConnection>>,
chan: rss::Channel,
chan: &rss::Channel,
parent: &Source,
) -> Result<()> {
let tempdb = mutex.lock().unwrap();
let pd = index_channel(&tempdb, &chan, parent)?;
let pd = index_channel(&tempdb, chan, parent)?;
drop(tempdb);
index_channel_items(mutex.clone(), chan.items(), &pd)?;
@@ -125,7 +126,7 @@ fn complete_index(
}
fn index_channel(db: &SqliteConnection, chan: &rss::Channel, parent: &Source) -> Result<Podcast> {
let pd = feedparser::parse_podcast(&chan, parent.id())?;
let pd = feedparser::parse_podcast(chan, parent.id())?;
// Convert NewPodcast to Podcast
let pd = insert_return_podcast(db, &pd)?;
Ok(pd)
@@ -138,13 +139,13 @@ fn index_channel_items(
pd: &Podcast,
) -> Result<()> {
let foo: Vec<_> = i.par_iter()
.map(|x| feedparser::parse_episode(&x, pd.id()).unwrap())
.map(|x| feedparser::parse_episode(x, pd.id()).unwrap())
.collect();
foo.par_iter().for_each(|x| {
let dbmutex = mutex.clone();
let db = dbmutex.lock().unwrap();
index_episode(&db, &x).unwrap();
index_episode(&db, x).unwrap();
});
Ok(())
}
@@ -315,7 +316,7 @@ mod tests {
let chan = rss::Channel::read_from(BufReader::new(feed)).unwrap();
// Index the channel
complete_index(m.clone(), chan, &s).unwrap();
complete_index(m.clone(), &chan, &s).unwrap();
})
.fold((), |(), _| ());
+1
View File
@@ -1,4 +1,5 @@
#![recursion_limit = "1024"]
#![cfg_attr(feature = "cargo-clippy", allow(blacklisted_name))]
#[macro_use]
extern crate error_chain;