From b528c48e3b7258ae16b9970eea772e5fca61c507 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sat, 9 Dec 2017 05:57:16 +0200 Subject: [PATCH] Run rustfmt. --- .gitlab-ci.yml | 2 ++ hammond-data/src/dbqueries.rs | 9 +++--- hammond-data/src/feed.rs | 9 +++--- hammond-data/src/lib.rs | 2 +- hammond-data/src/models/queryables.rs | 6 ++-- hammond-data/src/parser.rs | 42 +++++++++++++-------------- hammond-data/src/utils.rs | 9 +++--- hammond-downloader/src/downloader.rs | 19 ++++++------ hammond-gtk/src/content.rs | 35 +++++++++++----------- hammond-gtk/src/widgets/episode.rs | 2 +- 10 files changed, 68 insertions(+), 67 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 1bc2bbc..8726f9e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -40,6 +40,8 @@ nightly:test: rustfmt: image: "rustlang/rust:nightly" stage: lint + variables: + CFG_RELEASE_CHANNEL: "nightly" script: - rustc --version && cargo --version - cargo install rustfmt-nightly diff --git a/hammond-data/src/dbqueries.rs b/hammond-data/src/dbqueries.rs index f4c0791..1604547 100644 --- a/hammond-data/src/dbqueries.rs +++ b/hammond-data/src/dbqueries.rs @@ -198,9 +198,10 @@ pub fn update_none_to_played_now(parent: &Podcast) -> Result { let epoch_now = Utc::now().timestamp() as i32; con.transaction(|| -> Result { - Ok(diesel::update( - Episode::belonging_to(parent).filter(played.is_null()), - ).set(played.eq(Some(epoch_now))) - .execute(&*con)?) + Ok( + diesel::update(Episode::belonging_to(parent).filter(played.is_null())) + .set(played.eq(Some(epoch_now))) + .execute(&*con)?, + ) }) } diff --git a/hammond-data/src/feed.rs b/hammond-data/src/feed.rs index a87f98f..af38f1a 100644 --- a/hammond-data/src/feed.rs +++ b/hammond-data/src/feed.rs @@ -276,13 +276,12 @@ mod tests { f2.get_episodes().unwrap() }; - eps1.into_par_iter() - .zip(eps2) - .into_par_iter() - .for_each(|(ep1, ep2): (Episode, Episode)| { + eps1.into_par_iter().zip(eps2).into_par_iter().for_each( + |(ep1, ep2): (Episode, Episode)| { assert_eq!(ep1, ep2); assert_eq!(ep1.id(), ep2.id()); assert_eq!(ep1.podcast_id(), ep2.podcast_id()); - }); + }, + ); } } diff --git a/hammond-data/src/lib.rs b/hammond-data/src/lib.rs index b4465f1..9828740 100644 --- a/hammond-data/src/lib.rs +++ b/hammond-data/src/lib.rs @@ -37,6 +37,7 @@ extern crate diesel_migrations; #[macro_use] extern crate derive_builder; +extern crate ammonia; extern crate chrono; extern crate r2d2; extern crate r2d2_diesel; @@ -46,7 +47,6 @@ extern crate rfc822_sanitizer; extern crate rss; extern crate url; extern crate xdg; -extern crate ammonia; #[allow(missing_docs)] pub mod dbqueries; diff --git a/hammond-data/src/models/queryables.rs b/hammond-data/src/models/queryables.rs index 2e991df..2e41ea6 100644 --- a/hammond-data/src/models/queryables.rs +++ b/hammond-data/src/models/queryables.rs @@ -342,9 +342,9 @@ impl<'a> Source { let lmod = headers.get::(); // FIXME: This dsnt work most of the time apparently - if self.http_etag() != etag.map(|x| x.tag()) - || self.last_modified != lmod.map(|x| format!("{}", x)) - { + if self.http_etag() != etag.map(|x| x.tag()) || self.last_modified != lmod.map(|x| { + format!("{}", x) + }) { self.http_etag = etag.map(|x| x.tag().to_string().to_owned()); self.last_modified = lmod.map(|x| format!("{}", x)); self.save()?; diff --git a/hammond-data/src/parser.rs b/hammond-data/src/parser.rs index 2cddc50..97043a5 100644 --- a/hammond-data/src/parser.rs +++ b/hammond-data/src/parser.rs @@ -62,19 +62,17 @@ pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result { let length = item.enclosure().map(|x| x.length().parse().unwrap_or(0)); - Ok( - NewEpisodeBuilder::default() - .title(title) - .uri(uri) - .description(description) - .length(length) - .published_date(pub_date) - .epoch(epoch) - .guid(guid) - .podcast_id(parent_id) - .build() - .unwrap() - ) + Ok(NewEpisodeBuilder::default() + .title(title) + .uri(uri) + .description(description) + .length(length) + .published_date(pub_date) + .epoch(epoch) + .guid(guid) + .podcast_id(parent_id) + .build() + .unwrap()) } @@ -278,9 +276,9 @@ mod tests { let firstitem = channel.items().first().unwrap(); let descr = "Audit your network with a couple of easy commands on Kali Linux. Chris \ - decides to blow off a little steam by attacking his IoT devices, Wes has \ - the scope on Equifax blaming open source & the Beard just saved the \ - show. It’s a really packed episode!"; + decides to blow off a little steam by attacking his IoT devices, Wes has the \ + scope on Equifax blaming open source & the Beard just saved the show. \ + It’s a really packed episode!"; let i = new_episode(&firstitem, 0).unwrap(); assert_eq!(i.title(), Some("Hacking Devices with Kali Linux | LUP 214")); @@ -321,9 +319,8 @@ mod tests { let channel = Channel::read_from(BufReader::new(file)).unwrap(); let firstitem = channel.items().iter().nth(9).unwrap(); - let descr = "This week we look at RFC 2094 \"Non-lexical lifetimes\""; + let descr = "This week we look at RFC 2094 \"Non-lexical lifetimes\""; let i = new_episode(&firstitem, 0).unwrap(); assert_eq!(i.title(), Some("Episode #9 - A Once in a Lifetime RFC")); @@ -344,9 +341,10 @@ mod tests { let second = channel.items().iter().nth(8).unwrap(); let i2 = new_episode(&second, 0).unwrap(); - let descr2 = "This week we look at RFC 2071 \"Add impl Trait type alias and \ - variable declarations\""; + let descr2 = "This week we look at RFC 2071 \"Add impl Trait type alias and variable \ + declarations\""; assert_eq!(i2.title(), Some("Episode #8 - An Existential Crisis")); assert_eq!( i2.uri(), diff --git a/hammond-data/src/utils.rs b/hammond-data/src/utils.rs index e342151..d297102 100644 --- a/hammond-data/src/utils.rs +++ b/hammond-data/src/utils.rs @@ -109,9 +109,10 @@ pub fn url_cleaner(s: &str) -> String { // TODO: Docs pub fn replace_extra_spaces(s: &str) -> String { s.lines() - .map(|x| x.split_whitespace().collect::>().join(" ")) - .filter(|x| !x.is_empty()) - .collect::>().join("\n") + .map(|x| x.split_whitespace().collect::>().join(" ")) + .filter(|x| !x.is_empty()) + .collect::>() + .join("\n") } #[cfg(test)] @@ -151,7 +152,7 @@ mod tests { .unwrap() .into_episode(&con) .unwrap(); - + let mut ep1 = dbqueries::get_episode_from_uri(&con, "foo_bar").unwrap(); let mut ep2 = dbqueries::get_episode_from_uri(&con, "bar_baz").unwrap(); ep1.set_local_uri(Some(valid_path.to_str().unwrap())); diff --git a/hammond-downloader/src/downloader.rs b/hammond-downloader/src/downloader.rs index 97b1752..f3b695a 100644 --- a/hammond-downloader/src/downloader.rs +++ b/hammond-downloader/src/downloader.rs @@ -60,15 +60,16 @@ fn download_into(dir: &str, file_title: &str, url: &str) -> Result { // Determine the file extension from the http content-type header. fn get_ext(content: Option) -> Option { let cont = content.clone()?; - content.and_then(|c| mime_guess::get_extensions(c.type_().as_ref(), c.subtype().as_ref())) - .and_then(|c| { - if c.contains(&cont.subtype().as_ref()) { - Some(cont.subtype().as_ref().to_string()) - } else { - Some(c.first().unwrap().to_string()) - } - }) -} + content + .and_then(|c| mime_guess::get_extensions(c.type_().as_ref(), c.subtype().as_ref())) + .and_then(|c| { + if c.contains(&cont.subtype().as_ref()) { + Some(cont.subtype().as_ref().to_string()) + } else { + Some(c.first().unwrap().to_string()) + } + }) +} // TODO: Write unit-tests. /// Handles the I/O of fetching a remote file and saving into a Buffer and A File. diff --git a/hammond-gtk/src/content.rs b/hammond-gtk/src/content.rs index e8c359f..249f589 100644 --- a/hammond-gtk/src/content.rs +++ b/hammond-gtk/src/content.rs @@ -46,7 +46,7 @@ impl Content { self.podcasts.init(&self.stack); if self.podcasts.flowbox.get_children().is_empty() { self.stack.set_visible_child_name("empty"); - return + return; } self.stack.set_visible_child_name("podcasts"); @@ -100,9 +100,9 @@ impl Into> for ContentState { fn into(self) -> ContentState { self.content.stack.set_visible_child_name("podcasts"); - ContentState{ + ContentState { content: self.content, - state: PodcastsView{}, + state: PodcastsView {}, } } } @@ -114,9 +114,9 @@ impl UpdateView for ContentState { impl Into> for ContentState { fn into(self) -> ContentState { self.content.stack.set_visible_child_name("empty"); - ContentState{ + ContentState { content: self.content, - state: Empty{}, + state: Empty {}, } } } @@ -125,9 +125,9 @@ impl Into> for ContentState { fn into(self) -> ContentState { self.content.stack.set_visible_child_name("widget"); - ContentState{ + ContentState { content: self.content, - state: WidgetsView{}, + state: WidgetsView {}, } } } @@ -142,9 +142,9 @@ impl UpdateView for ContentState { impl Into> for ContentState { fn into(self) -> ContentState { self.content.stack.set_visible_child_name("podcasts"); - ContentState{ + ContentState { content: self.content, - state: PodcastsView{}, + state: PodcastsView {}, } } } @@ -152,9 +152,9 @@ impl Into> for ContentState { impl Into> for ContentState { fn into(self) -> ContentState { self.content.stack.set_visible_child_name("empty"); - ContentState{ + ContentState { content: self.content, - state: Empty{}, + state: Empty {}, } } } @@ -165,7 +165,7 @@ impl UpdateView for ContentState { let id = WidgetExt::get_name(&old).unwrap(); let pd = dbqueries::get_podcast_from_id(id.parse::().unwrap()).unwrap(); - let pdw = PodcastWidget::new_initialized(&self.content.stack, &pd);; + let pdw = PodcastWidget::new_initialized(&self.content.stack, &pd); self.content.replace_widget(pdw); } } @@ -178,17 +178,16 @@ impl ContentState { content.podcasts.init(&content.stack); if content.podcasts.flowbox.get_children().is_empty() { content.stack.set_visible_child_name("empty"); - return Err( - ContentState{ - content, - state: Empty{}, - }); + return Err(ContentState { + content, + state: Empty {}, + }); } content.stack.set_visible_child_name("podcasts"); Ok(ContentState { content, - state: PodcastsView{}, + state: PodcastsView {}, }) } diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index 4c61aac..c113b51 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -90,7 +90,7 @@ impl EpisodeWidget { // let mut text = text.clone(); // html_to_markup(&mut text); // description.set_markup(&text) - + let plain_text = strip_html_tags(&text).join(" "); // TODO: handle unwrap let buff = description.get_buffer().unwrap();