Cargo clippy and fmt.

This commit is contained in:
Jordan Petridis 2018-02-19 09:58:47 +00:00
parent 038d28779c
commit ae25dd65bf
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
19 changed files with 81 additions and 50 deletions

View File

@ -96,7 +96,7 @@ impl Feed {
// I am not sure what the optimizations are on match vs allocating None.
.map(|fut| {
fut.and_then(|x| match x {
IndexState::NotChanged => return Err(DataError::EpisodeNotChanged),
IndexState::NotChanged => Err(DataError::EpisodeNotChanged),
_ => Ok(x),
})
})

View File

@ -32,7 +32,8 @@ pub struct Episode {
}
impl Save<Episode, DataError> for Episode {
/// Helper method to easily save/"sync" current state of self to the Database.
/// Helper method to easily save/"sync" current state of self to the
/// Database.
fn save(&self) -> Result<Episode, DataError> {
let db = connection();
let tempdb = db.get()?;
@ -224,7 +225,8 @@ impl From<Episode> for EpisodeWidgetQuery {
}
impl Save<usize, DataError> for EpisodeWidgetQuery {
/// Helper method to easily save/"sync" current state of self to the Database.
/// Helper method to easily save/"sync" current state of self to the
/// Database.
fn save(&self) -> Result<usize, DataError> {
use schema::episode::dsl::*;
@ -362,7 +364,8 @@ pub struct EpisodeCleanerQuery {
}
impl Save<usize, DataError> for EpisodeCleanerQuery {
/// Helper method to easily save/"sync" current state of self to the Database.
/// Helper method to easily save/"sync" current state of self to the
/// Database.
fn save(&self) -> Result<usize, DataError> {
use schema::episode::dsl::*;

View File

@ -45,6 +45,7 @@ pub trait Index<T, E>: Insert<T, E> + Update<T, E> {
/// FIXME: DOCS
pub trait Save<T, E> {
/// Helper method to easily save/"sync" current state of a diesel model to the Database.
/// Helper method to easily save/"sync" current state of a diesel model to
/// the Database.
fn save(&self) -> Result<T, E>;
}

View File

@ -74,7 +74,8 @@ impl Update<(), DataError> for NewEpisode {
}
impl Index<(), DataError> for NewEpisode {
// Does not update the episode description if it's the only thing that has changed.
// Does not update the episode description if it's the only thing that has
// changed.
fn index(&self) -> Result<(), DataError> {
let exists = dbqueries::episode_exists(self.title(), self.podcast_id())?;
@ -185,7 +186,7 @@ impl NewEpisodeMinimal {
pub(crate) fn new(item: &rss::Item, parent_id: i32) -> Result<Self, DataError> {
if item.title().is_none() {
let err = DataError::ParseEpisodeError {
reason: format!("No title specified for this Episode."),
reason: "No title specified for this Episode.".into(),
parent_id,
};
@ -201,7 +202,7 @@ impl NewEpisodeMinimal {
item.link().map(|s| url_cleaner(s))
} else {
let err = DataError::ParseEpisodeError {
reason: format!("No url specified for the item."),
reason: "No url specified for the item.".into(),
parent_id,
};

View File

@ -343,7 +343,8 @@ mod tests {
#[test]
// TODO: Add more test/checks
// Currently there's a test that only checks new description or title.
// If you have time and want to help, implement the test for the other fields too.
// If you have time and want to help, implement the test for the other fields
// too.
fn test_new_podcast_update() {
truncate_db().unwrap();
let old = EXPECTED_INTERCEPTED.to_podcast().unwrap();

View File

@ -26,7 +26,8 @@ pub struct Podcast {
}
impl Save<Podcast, DataError> for Podcast {
/// Helper method to easily save/"sync" current state of self to the Database.
/// Helper method to easily save/"sync" current state of self to the
/// Database.
fn save(&self) -> Result<Podcast, DataError> {
let db = connection();
let tempdb = db.get()?;

View File

@ -34,7 +34,8 @@ pub struct Source {
}
impl Save<Source, DataError> for Source {
/// Helper method to easily save/"sync" current state of self to the Database.
/// Helper method to easily save/"sync" current state of self to the
/// Database.
fn save(&self) -> Result<Source, DataError> {
let db = connection();
let con = db.get()?;
@ -119,7 +120,7 @@ impl Source {
let err = DataError::HttpStatusError {
url: self.uri,
status_code: code,
context: format!("304: skipping.."),
context: "304: skipping..".into(),
};
return Err(err);
@ -131,7 +132,7 @@ impl Source {
let err = DataError::HttpStatusError {
url: self.uri,
status_code: code,
context: format!("301: Feed was moved permanently."),
context: "301: Feed was moved permanently.".into(),
};
return Err(err);
@ -142,7 +143,7 @@ impl Source {
let err = DataError::HttpStatusError {
url: self.uri,
status_code: code,
context: format!("401: Unauthorized."),
context: "401: Unauthorized.".into(),
};
return Err(err);
@ -151,17 +152,25 @@ impl Source {
let err = DataError::HttpStatusError {
url: self.uri,
status_code: code,
context: format!("403: Forbidden."),
context: "403: Forbidden.".into(),
};
return Err(err);
}
StatusCode::NotFound => {
let err = DataError::HttpStatusError {
url: self.uri,
status_code: code,
context: "404: Not found.".into(),
};
return Err(err);
}
StatusCode::NotFound => return Err(format!("404: Not found.")).map_err(From::from),
StatusCode::RequestTimeout => {
let err = DataError::HttpStatusError {
url: self.uri,
status_code: code,
context: format!("408: Request Timeout."),
context: "408: Request Timeout.".into(),
};
return Err(err);
@ -170,7 +179,7 @@ impl Source {
let err = DataError::HttpStatusError {
url: self.uri,
status_code: code,
context: format!("410: Feed was deleted.."),
context: "410: Feed was deleted..".into(),
};
return Err(err);
@ -267,6 +276,7 @@ impl Source {
}
}
#[allow(needless_pass_by_value)]
fn response_to_channel(
res: Response,
pool: CpuPool,

View File

@ -67,7 +67,8 @@ pub fn pipeline<S: IntoIterator<Item = Source>>(
Ok(())
}
/// Creates a tokio `reactor::Core`, a `CpuPool`, and a `hyper::Client` and runs the pipeline.
/// Creates a tokio `reactor::Core`, a `CpuPool`, and a `hyper::Client` and
/// runs the pipeline.
pub fn run(sources: Vec<Source>, ignore_etags: bool) -> Result<(), DataError> {
if sources.is_empty() {
return Ok(());

View File

@ -14,7 +14,8 @@ use xdg_dirs::DL_DIR;
use std::fs;
use std::path::Path;
/// Scan downloaded `episode` entries that might have broken `local_uri`s and set them to `None`.
/// Scan downloaded `episode` entries that might have broken `local_uri`s and
/// set them to `None`.
fn download_checker() -> Result<(), DataError> {
let mut episodes = dbqueries::get_downloaded_episodes()?;

View File

@ -18,7 +18,8 @@ use hammond_data::xdg_dirs::HAMMOND_CACHE;
use errors::DownloadError;
// TODO: Replace path that are of type &str with std::path.
// TODO: Have a convention/document absolute/relative paths, if they should end with / or not.
// TODO: Have a convention/document absolute/relative paths, if they should end
// with / or not.
pub trait DownloadProgress {
fn set_downloaded(&mut self, downloaded: u64);
@ -75,7 +76,8 @@ fn download_into(
info!("Extension: {}", ext);
// Construct a temp file to save desired content.
// It has to be a `new_in` instead of new cause rename can't move cross filesystems.
// It has to be a `new_in` instead of new cause rename can't move cross
// filesystems.
let tempdir = TempDir::new_in(HAMMOND_CACHE.to_str().unwrap(), "temp_download")?;
let out_file = format!("{}/temp.part", tempdir.path().to_str().unwrap(),);
@ -113,7 +115,9 @@ fn get_ext(content: Option<ContentType>) -> Option<String> {
// TODO: Write unit-tests.
// TODO: Refactor... Somehow.
/// Handles the I/O of fetching a remote file and saving into a Buffer and A File.
/// Handles the I/O of fetching a remote file and saving into a Buffer and A
/// File.
#[allow(needless_pass_by_value)]
fn save_io(
file: &str,
resp: &mut reqwest::Response,

View File

@ -1,5 +1,7 @@
#![recursion_limit = "1024"]
#![deny(unused_extern_crates, unused)]
#![allow(unknown_lints)]
#![cfg_attr(feature = "cargo-clippy", allow(blacklisted_name))]
extern crate failure;
#[macro_use]

View File

@ -1,3 +1,5 @@
#![allow(new_without_default)]
use gio::{ApplicationExt, ApplicationExtManual, ApplicationFlags};
use glib;
use gtk;

View File

@ -1,5 +1,7 @@
#![cfg_attr(feature = "cargo-clippy", allow(clone_on_ref_ptr, needless_pass_by_value))]
// #![deny(unused_extern_crates, unused)]
#![cfg_attr(feature = "cargo-clippy",
allow(clone_on_ref_ptr, needless_pass_by_value, useless_format))]
#![allow(unknown_lints)]
#![deny(unused_extern_crates, unused)]
extern crate gdk;
extern crate gdk_pixbuf;

View File

@ -102,8 +102,9 @@ impl ShowStack {
debug!("Name: {:?}", WidgetExt::get_name(&old));
let new = ShowWidget::new(pd, self.sender.clone());
// Each composite ShowWidget is a gtkBox with the Podcast.id encoded in the gtk::Widget
// name. It's a hack since we can't yet subclass GObject easily.
// Each composite ShowWidget is a gtkBox with the Podcast.id encoded in the
// gtk::Widget name. It's a hack since we can't yet subclass GObject
// easily.
let oldid = WidgetExt::get_name(&old);
let newid = WidgetExt::get_name(&new.container);
debug!("Old widget Name: {:?}\nNew widget Name: {:?}", oldid, newid);

View File

@ -2,14 +2,16 @@ use gio::{resources_register, Error, Resource};
use glib::Bytes;
pub fn init() -> Result<(), Error> {
// load the gresource binary at build time and include/link it into the final binary.
// load the gresource binary at build time and include/link it into the final
// binary.
let res_bytes = include_bytes!("../resources/resources.gresource");
// Create Resource it will live as long the value lives.
let gbytes = Bytes::from_static(res_bytes.as_ref());
let resource = Resource::new_from_data(&gbytes)?;
// Register the resource so It wont be dropped and will continue to live in memory.
// Register the resource so It wont be dropped and will continue to live in
// memory.
resources_register(&resource);
Ok(())

View File

@ -36,13 +36,14 @@ fn refresh_feed(source: Option<Vec<Source>>, sender: Sender<Action>) -> Result<(
});
// Work around to improve the feed addition experience.
// Many times links to rss feeds are just redirects(usually to an https version).
// Sadly I haven't figured yet a nice way to follow up links redirects without getting
// to lifetime hell with futures and hyper.
// Many times links to rss feeds are just redirects(usually to an https
// version). Sadly I haven't figured yet a nice way to follow up links
// redirects without getting to lifetime hell with futures and hyper.
// So the requested refresh is only of 1 feed, and the feed fails to be indexed,
// (as a 301 redict would update the source entry and exit), another refresh is run.
// For more see hammond_data/src/models/source.rs `fn request_constructor`.
// also ping me on irc if or open an issue if you want to tackle it.
// (as a 301 redict would update the source entry and exit), another refresh is
// run. For more see hammond_data/src/models/source.rs `fn
// request_constructor`. also ping me on irc if or open an issue if you
// want to tackle it.
if sources.len() == 1 {
let source = sources.remove(0);
let id = source.id();
@ -56,12 +57,10 @@ fn refresh_feed(source: Option<Vec<Source>>, sender: Sender<Action>) -> Result<(
}
}
}
} else {
// This is what would normally run
if let Err(err) = pipeline::run(sources, false) {
error!("Error While trying to update the database.");
error!("Error msg: {}", err);
}
// This is what would normally run
} else if let Err(err) = pipeline::run(sources, false) {
error!("Error While trying to update the database.");
error!("Error msg: {}", err);
}
sender

View File

@ -56,13 +56,10 @@ impl ShowsPopulated {
fn populate_flowbox(&self) -> Result<(), Error> {
let podcasts = dbqueries::get_podcasts()?;
podcasts
.into_iter()
.map(|pd| Arc::new(pd))
.for_each(|parent| {
let flowbox_child = ShowsChild::new(parent);
self.flowbox.add(&flowbox_child.child);
});
podcasts.into_iter().map(Arc::new).for_each(|parent| {
let flowbox_child = ShowsChild::new(parent);
self.flowbox.add(&flowbox_child.child);
});
self.flowbox.show_all();
Ok(())
}

View File

@ -159,7 +159,8 @@ impl EpisodeWidget {
}));
}
/// Show or hide the play/delete/download buttons upon widget initialization.
/// Show or hide the play/delete/download buttons upon widget
/// initialization.
fn show_buttons(&self, local_uri: Option<&str>) -> Result<(), Error> {
let path = local_uri.ok_or_else(|| format_err!("Path is None"))?;
if Path::new(path).exists() {
@ -329,6 +330,7 @@ fn update_progressbar_callback(
);
}
#[allow(if_same_then_else)]
fn progress_bar_helper(
prog: Arc<Mutex<manager::Progress>>,
episode_rowid: i32,

View File

@ -105,7 +105,8 @@ impl ShowWidget {
/// Set the descripton text.
fn set_description(&self, text: &str) {
// TODO: Temporary solution until we render html urls/bold/italic probably with markup.
// TODO: Temporary solution until we render html urls/bold/italic probably with
// markup.
let desc = dissolve::strip_html_tags(text).join(" ");
self.description.set_text(&replace_extra_spaces(&desc));
}