From 990d830f24762a6740604c6c9cba80efbf42287c Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 23 Oct 2018 13:22:35 +0300 Subject: [PATCH] cargo fmt --- .gitlab-ci.yml | 3 +-- podcasts-data/src/dbqueries.rs | 3 ++- podcasts-data/src/errors.rs | 9 ++----- podcasts-data/src/feed.rs | 6 +++-- podcasts-data/src/models/new_episode.rs | 27 ++++++++++++------- podcasts-data/src/models/new_show.rs | 6 +++-- podcasts-data/src/models/source.rs | 35 ++++++++++++++++--------- podcasts-data/src/opml.rs | 6 +++-- podcasts-data/src/pipeline.rs | 9 +++---- podcasts-data/src/utils.rs | 3 ++- podcasts-downloader/src/downloader.rs | 2 +- podcasts-downloader/src/lib.rs | 13 ++------- podcasts-gtk/src/main.rs | 10 ++----- podcasts-gtk/src/prefs.rs | 4 +-- podcasts-gtk/src/widgets/player.rs | 10 ++++--- rustfmt.toml | 1 - 16 files changed, 75 insertions(+), 72 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fa7b08a..7edf293 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -93,5 +93,4 @@ rustfmt: script: - rustc -Vv && cargo -Vv - cargo fmt --version - - cargo fmt --all -- --check - allow_failure: true \ No newline at end of file + - cargo fmt --all -- --check \ No newline at end of file diff --git a/podcasts-data/src/dbqueries.rs b/podcasts-data/src/dbqueries.rs index 22e9d96..be2349e 100644 --- a/podcasts-data/src/dbqueries.rs +++ b/podcasts-data/src/dbqueries.rs @@ -110,7 +110,8 @@ pub fn get_episode_widget_from_rowid(ep_id: i32) -> Result(&con) .map_err(From::from) } diff --git a/podcasts-data/src/errors.rs b/podcasts-data/src/errors.rs index bee3044..c24e05b 100644 --- a/podcasts-data/src/errors.rs +++ b/podcasts-data/src/errors.rs @@ -14,9 +14,7 @@ use models::Source; #[fail( display = "Request to {} returned {}. Context: {}", - url, - status_code, - context + url, status_code, context )] #[derive(Fail, Debug)] pub struct HttpStatusError { @@ -67,10 +65,7 @@ pub enum DataError { FeedRedirect(Source), #[fail(display = "Feed is up to date")] FeedNotModified(Source), - #[fail( - display = "Error occured while Parsing an Episode. Reason: {}", - reason - )] + #[fail(display = "Error occured while Parsing an Episode. Reason: {}", reason)] ParseEpisodeError { reason: String, parent_id: i32 }, #[fail(display = "Episode was not changed and thus skipped.")] EpisodeNotChanged, diff --git a/podcasts-data/src/feed.rs b/podcasts-data/src/feed.rs index 9153823..adcf48a 100644 --- a/podcasts-data/src/feed.rs +++ b/podcasts-data/src/feed.rs @@ -108,7 +108,8 @@ fn batch_insert_episodes(episodes: &[NewEpisode]) { .map_err(|err| { error!("Failed batch indexng: {}", err); info!("Fallign back to individual indexing."); - }).unwrap_or_else(|_| { + }) + .unwrap_or_else(|_| { episodes.iter().for_each(|ep| { ep.index() .map_err(|err| error!("Error: {}.", err)) @@ -174,7 +175,8 @@ mod tests { // Create and insert a Source into db let s = Source::from_url(url).unwrap(); get_feed(path, s.id()) - }).collect(); + }) + .collect(); // Index the channes let stream_ = stream::iter_ok(feeds).for_each(|x| x.index()); diff --git a/podcasts-data/src/models/new_episode.rs b/podcasts-data/src/models/new_episode.rs index fe24078..dd240bc 100644 --- a/podcasts-data/src/models/new_episode.rs +++ b/podcasts-data/src/models/new_episode.rs @@ -332,7 +332,8 @@ mod tests { .title("The Super Bowl of Racism") .uri(Some(String::from( "http://traffic.megaphone.fm/PPY6458293736.mp3", - ))).guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24"))) + ))) + .guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24"))) .epoch(1505296800) .length(Some(66738886)) .duration(Some(4171)) @@ -345,7 +346,8 @@ mod tests { .title("Atlas Golfed — U.S.-Backed Think Tanks Target Latin America") .uri(Some(String::from( "http://traffic.megaphone.fm/FL5331443769.mp3", - ))).guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d"))) + ))) + .guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d"))) .epoch(1502272800) .length(Some(67527575)) .duration(Some(4415)) @@ -364,7 +366,8 @@ mod tests { .title("The Super Bowl of Racism") .uri(Some(String::from( "http://traffic.megaphone.fm/PPY6458293736.mp3", - ))).description(Some(String::from(descr))) + ))) + .description(Some(String::from(descr))) .guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24"))) .length(Some(66738886)) .epoch(1505296800) @@ -387,7 +390,8 @@ mod tests { .title("Atlas Golfed — U.S.-Backed Think Tanks Target Latin America") .uri(Some(String::from( "http://traffic.megaphone.fm/FL5331443769.mp3", - ))).description(Some(String::from(descr))) + ))) + .description(Some(String::from(descr))) .guid(Some(String::from("7c207a24-e33f-11e6-9438-eb45dcf36a1d"))) .length(Some(67527575)) .epoch(1502272800) @@ -401,7 +405,8 @@ mod tests { .title("The Super Bowl of Racism") .uri(Some(String::from( "http://traffic.megaphone.fm/PPY6458293736.mp3", - ))).description(Some(String::from("New description"))) + ))) + .description(Some(String::from("New description"))) .guid(Some(String::from("7df4070a-9832-11e7-adac-cb37b05d5e24"))) .length(Some(66738886)) .epoch(1505296800) @@ -415,7 +420,8 @@ mod tests { .title("Hacking Devices with Kali Linux | LUP 214") .uri(Some(String::from( "http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3", - ))).guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D"))) + ))) + .guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D"))) .length(Some(46479789)) .epoch(1505280282) .duration(Some(5733)) @@ -428,7 +434,8 @@ mod tests { .title("Gnome Does it Again | LUP 213") .uri(Some(String::from( "http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3", - ))).guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B"))) + ))) + .guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B"))) .epoch(1504670247) .length(Some(36544272)) .duration(Some(4491)) @@ -446,7 +453,8 @@ mod tests { .title("Hacking Devices with Kali Linux | LUP 214") .uri(Some(String::from( "http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3", - ))).description(Some(String::from(descr))) + ))) + .description(Some(String::from(descr))) .guid(Some(String::from("78A682B4-73E8-47B8-88C0-1BE62DD4EF9D"))) .length(Some(46479789)) .epoch(1505280282) @@ -467,7 +475,8 @@ mod tests { .title("Gnome Does it Again | LUP 213") .uri(Some(String::from( "http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3", - ))).description(Some(String::from(descr))) + ))) + .description(Some(String::from(descr))) .guid(Some(String::from("1CE57548-B36C-4F14-832A-5D5E0A24E35B"))) .length(Some(36544272)) .epoch(1504670247) diff --git a/podcasts-data/src/models/new_show.rs b/podcasts-data/src/models/new_show.rs index 99cfcbe..a275b68 100644 --- a/podcasts-data/src/models/new_show.rs +++ b/podcasts-data/src/models/new_show.rs @@ -200,7 +200,8 @@ mod tests { .description(descr) .image_uri(Some(String::from( "http://www.jupiterbroadcasting.com/images/LASUN-Badge1400.jpg", - ))).source_id(42) + ))) + .source_id(42) .build() .unwrap() }; @@ -256,7 +257,8 @@ mod tests { .description(descr) .image_uri(Some(String::from( "http://www.greaterthancode.com/wp-content/uploads/2016/10/code1400-4.jpg", - ))).source_id(42) + ))) + .source_id(42) .build() .unwrap() }; diff --git a/podcasts-data/src/models/source.rs b/podcasts-data/src/models/source.rs index db48441..7a36f43 100644 --- a/podcasts-data/src/models/source.rs +++ b/podcasts-data/src/models/source.rs @@ -4,14 +4,14 @@ use rss::Channel; use url::Url; use hyper::client::HttpConnector; -use hyper::{Client, Body}; +use hyper::{Body, Client}; use hyper_tls::HttpsConnector; -use http::{Request, Response, StatusCode, Uri}; use http::header::{ - ETAG, IF_MODIFIED_SINCE, IF_NONE_MATCH, LAST_MODIFIED, LOCATION, USER_AGENT as USER_AGENT_HEADER, - HeaderValue, + HeaderValue, ETAG, IF_MODIFIED_SINCE, IF_NONE_MATCH, LAST_MODIFIED, LOCATION, + USER_AGENT as USER_AGENT_HEADER, }; +use http::{Request, Response, StatusCode, Uri}; // use futures::future::ok; use futures::future::{loop_fn, Future, Loop}; use futures::prelude::*; @@ -96,8 +96,14 @@ impl Source { fn update_etag(mut self, res: &Response) -> Result { let headers = res.headers(); - let etag = headers.get(ETAG).and_then(|h| h.to_str().ok()).map(From::from); - let lmod = headers.get(LAST_MODIFIED).and_then(|h| h.to_str().ok()).map(From::from); + let etag = headers + .get(ETAG) + .and_then(|h| h.to_str().ok()) + .map(From::from); + let lmod = headers + .get(LAST_MODIFIED) + .and_then(|h| h.to_str().ok()) + .map(From::from); if (self.http_etag() != etag) || (self.last_modified != lmod) { self.set_http_etag(etag); @@ -249,19 +255,20 @@ impl Source { ) -> impl Future, Error = DataError> { // FIXME: remove unwrap somehow let uri = Uri::from_str(self.uri()).unwrap(); - let mut req = Request::get(uri) - .body(Body::empty()) - .unwrap(); + let mut req = Request::get(uri).body(Body::empty()).unwrap(); // Set the UserAgent cause ppl still seem to check it for some reason... - req.headers_mut().insert(USER_AGENT_HEADER, HeaderValue::from_static(USER_AGENT)); + req.headers_mut() + .insert(USER_AGENT_HEADER, HeaderValue::from_static(USER_AGENT)); if let Some(etag) = self.http_etag() { - req.headers_mut().insert(IF_NONE_MATCH, HeaderValue::from_str(etag).unwrap()); + req.headers_mut() + .insert(IF_NONE_MATCH, HeaderValue::from_str(etag).unwrap()); } if let Some(lmod) = self.last_modified() { - req.headers_mut().insert(IF_MODIFIED_SINCE, HeaderValue::from_str(lmod).unwrap()); + req.headers_mut() + .insert(IF_MODIFIED_SINCE, HeaderValue::from_str(lmod).unwrap()); } client @@ -271,7 +278,9 @@ impl Source { } } -fn response_to_channel(res: Response) -> impl Future + Send { +fn response_to_channel( + res: Response, +) -> impl Future + Send { res.into_body() .concat2() .map(|x| x.into_iter()) diff --git a/podcasts-data/src/opml.rs b/podcasts-data/src/opml.rs index c4e0bfb..b195543 100644 --- a/podcasts-data/src/opml.rs +++ b/podcasts-data/src/opml.rs @@ -42,7 +42,8 @@ pub fn import_to_db(reader: R) -> Result, reader::Error> { } s.ok() - }).collect(); + }) + .collect(); Ok(feeds) } @@ -91,7 +92,8 @@ pub fn extract_sources(reader: R) -> Result, reader::Erro } Err(err) => Err(err), _ => Ok(()), - }).collect::, reader::Error>>()?; + }) + .collect::, reader::Error>>()?; Ok(list) } diff --git a/podcasts-data/src/pipeline.rs b/podcasts-data/src/pipeline.rs index dac255e..475a90d 100644 --- a/podcasts-data/src/pipeline.rs +++ b/podcasts-data/src/pipeline.rs @@ -1,11 +1,11 @@ // FIXME: //! Docs. -use futures::{lazy, prelude::*, future::ok, stream::FuturesUnordered}; +use futures::{future::ok, lazy, prelude::*, stream::FuturesUnordered}; use tokio; use hyper::client::HttpConnector; -use hyper::{Client, Body}; +use hyper::{Body, Client}; use hyper_tls::HttpsConnector; use num_cpus; @@ -23,10 +23,7 @@ type HttpsClient = Client>; /// Messy temp diagram: /// Source -> GET Request -> Update Etags -> Check Status -> Parse `xml/Rss` -> /// Convert `rss::Channel` into `Feed` -> Index Podcast -> Index Episodes. -pub fn pipeline<'a, S>( - sources: S, - client: HttpsClient, -) -> impl Future + 'a +pub fn pipeline<'a, S>(sources: S, client: HttpsClient) -> impl Future + 'a where S: Stream + Send + 'a, { diff --git a/podcasts-data/src/utils.rs b/podcasts-data/src/utils.rs index d32b66a..115e95f 100644 --- a/podcasts-data/src/utils.rs +++ b/podcasts-data/src/utils.rs @@ -25,7 +25,8 @@ fn download_checker() -> Result<(), DataError> { return Some(ep); } None - }).for_each(|ep| { + }) + .for_each(|ep| { ep.set_local_uri(None); ep.save() .map_err(|err| error!("{}", err)) diff --git a/podcasts-downloader/src/downloader.rs b/podcasts-downloader/src/downloader.rs index 475fb37..ae9970e 100644 --- a/podcasts-downloader/src/downloader.rs +++ b/podcasts-downloader/src/downloader.rs @@ -1,8 +1,8 @@ use glob::glob; use mime_guess; use reqwest; -use reqwest::RedirectPolicy; use reqwest::header::*; +use reqwest::RedirectPolicy; use tempdir::TempDir; use std::fs; diff --git a/podcasts-downloader/src/lib.rs b/podcasts-downloader/src/lib.rs index dd9a8c1..d3e95fa 100644 --- a/podcasts-downloader/src/lib.rs +++ b/podcasts-downloader/src/lib.rs @@ -1,17 +1,8 @@ #![recursion_limit = "1024"] #![allow(unknown_lints)] -#![cfg_attr( - feature = "cargo-clippy", - allow(blacklisted_name, option_map_unit_fn) -)] +#![cfg_attr(feature = "cargo-clippy", allow(blacklisted_name, option_map_unit_fn))] // Enable lint group collections -#![warn( - nonstandard_style, - edition_2018, - rust_2018_idioms, - bad_style, - unused -)] +#![warn(nonstandard_style, edition_2018, rust_2018_idioms, bad_style, unused)] // standalone lints #![warn( const_err, diff --git a/podcasts-gtk/src/main.rs b/podcasts-gtk/src/main.rs index 6d33831..ef35b7a 100644 --- a/podcasts-gtk/src/main.rs +++ b/podcasts-gtk/src/main.rs @@ -9,13 +9,7 @@ )] #![allow(unknown_lints)] // Enable lint group collections -#![warn( - nonstandard_style, - edition_2018, - rust_2018_idioms, - bad_style, - unused -)] +#![warn(nonstandard_style, edition_2018, rust_2018_idioms, bad_style, unused)] // standalone lints #![warn( const_err, @@ -66,6 +60,7 @@ extern crate html2text; extern crate humansize; extern crate libhandy; extern crate loggerv; +extern crate mpris_player; extern crate open; extern crate podcasts_data; extern crate podcasts_downloader; @@ -74,7 +69,6 @@ extern crate regex; extern crate reqwest; extern crate serde_json; extern crate url; -extern crate mpris_player; use log::Level; diff --git a/podcasts-gtk/src/prefs.rs b/podcasts-gtk/src/prefs.rs index b52dac6..49e8e62 100644 --- a/podcasts-gtk/src/prefs.rs +++ b/podcasts-gtk/src/prefs.rs @@ -62,8 +62,8 @@ impl Prefs { i18n("Days"), i18n("Weeks"), ] - .iter() - .enumerate() + .iter() + .enumerate() { let row: &[&dyn ToValue] = &[item]; if item.to_lowercase() == cleanup_p { diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index 947fe06..bcc0878 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -19,16 +19,16 @@ use podcasts_data::{EpisodeWidgetModel, ShowCoverModel}; use app::Action; use utils::set_image_from_path; +use std::cell::RefCell; use std::ops::Deref; use std::path::Path; use std::rc::Rc; -use std::cell::RefCell; use std::sync::Mutex; use i18n::i18n; +use mpris_player::{Metadata, MprisPlayer, OrgMprisMediaPlayer2Player, PlaybackStatus}; use std::sync::Arc; -use mpris_player::{PlaybackStatus, MprisPlayer, Metadata, OrgMprisMediaPlayer2Player}; #[derive(Debug, Clone, Copy)] enum SeekDirection { @@ -349,7 +349,9 @@ impl PlayerWidget { weak.upgrade().map(|p| p.rewind()); })); - s.info.mpris.connect_raise(clone!(sender => move || sender.send(Action::RaiseWindow))); + s.info + .mpris + .connect_raise(clone!(sender => move || sender.send(Action::RaiseWindow))); } #[cfg_attr(rustfmt, rustfmt_skip)] @@ -483,7 +485,7 @@ impl PlayerWidget { // Only rewind on pause if the stream position is passed a certain point, // and the player has been paused for more than a minute, // and the episode id is the same - if seconds_passed >= 90 && delta >= 60 && current_id == *last { + if seconds_passed >= 90 && delta >= 60 && current_id == *last { self.seek(ClockTime::from_seconds(5), SeekDirection::Backwards); } diff --git a/rustfmt.toml b/rustfmt.toml index 4f93342..16bfbd5 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -4,4 +4,3 @@ newline_style = "Unix" format_strings = true normalize_comments = true use_field_init_shorthand = true -edition = "Edition2018"