Run rustfmt.

This commit is contained in:
Jordan Petridis 2017-12-09 05:57:16 +02:00
parent 5b19274e6a
commit b528c48e3b
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
10 changed files with 68 additions and 67 deletions

View File

@ -40,6 +40,8 @@ nightly:test:
rustfmt: rustfmt:
image: "rustlang/rust:nightly" image: "rustlang/rust:nightly"
stage: lint stage: lint
variables:
CFG_RELEASE_CHANNEL: "nightly"
script: script:
- rustc --version && cargo --version - rustc --version && cargo --version
- cargo install rustfmt-nightly - cargo install rustfmt-nightly

View File

@ -198,9 +198,10 @@ pub fn update_none_to_played_now(parent: &Podcast) -> Result<usize> {
let epoch_now = Utc::now().timestamp() as i32; let epoch_now = Utc::now().timestamp() as i32;
con.transaction(|| -> Result<usize> { con.transaction(|| -> Result<usize> {
Ok(diesel::update( Ok(
Episode::belonging_to(parent).filter(played.is_null()), diesel::update(Episode::belonging_to(parent).filter(played.is_null()))
).set(played.eq(Some(epoch_now))) .set(played.eq(Some(epoch_now)))
.execute(&*con)?) .execute(&*con)?,
)
}) })
} }

View File

@ -276,13 +276,12 @@ mod tests {
f2.get_episodes().unwrap() f2.get_episodes().unwrap()
}; };
eps1.into_par_iter() eps1.into_par_iter().zip(eps2).into_par_iter().for_each(
.zip(eps2) |(ep1, ep2): (Episode, Episode)| {
.into_par_iter()
.for_each(|(ep1, ep2): (Episode, Episode)| {
assert_eq!(ep1, ep2); assert_eq!(ep1, ep2);
assert_eq!(ep1.id(), ep2.id()); assert_eq!(ep1.id(), ep2.id());
assert_eq!(ep1.podcast_id(), ep2.podcast_id()); assert_eq!(ep1.podcast_id(), ep2.podcast_id());
}); },
);
} }
} }

View File

@ -37,6 +37,7 @@ extern crate diesel_migrations;
#[macro_use] #[macro_use]
extern crate derive_builder; extern crate derive_builder;
extern crate ammonia;
extern crate chrono; extern crate chrono;
extern crate r2d2; extern crate r2d2;
extern crate r2d2_diesel; extern crate r2d2_diesel;
@ -46,7 +47,6 @@ extern crate rfc822_sanitizer;
extern crate rss; extern crate rss;
extern crate url; extern crate url;
extern crate xdg; extern crate xdg;
extern crate ammonia;
#[allow(missing_docs)] #[allow(missing_docs)]
pub mod dbqueries; pub mod dbqueries;

View File

@ -342,9 +342,9 @@ impl<'a> Source {
let lmod = headers.get::<LastModified>(); let lmod = headers.get::<LastModified>();
// FIXME: This dsnt work most of the time apparently // FIXME: This dsnt work most of the time apparently
if self.http_etag() != etag.map(|x| x.tag()) if self.http_etag() != etag.map(|x| x.tag()) || self.last_modified != lmod.map(|x| {
|| self.last_modified != lmod.map(|x| format!("{}", x)) format!("{}", x)
{ }) {
self.http_etag = etag.map(|x| x.tag().to_string().to_owned()); self.http_etag = etag.map(|x| x.tag().to_string().to_owned());
self.last_modified = lmod.map(|x| format!("{}", x)); self.last_modified = lmod.map(|x| format!("{}", x));
self.save()?; self.save()?;

View File

@ -62,8 +62,7 @@ pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
let length = item.enclosure().map(|x| x.length().parse().unwrap_or(0)); let length = item.enclosure().map(|x| x.length().parse().unwrap_or(0));
Ok( Ok(NewEpisodeBuilder::default()
NewEpisodeBuilder::default()
.title(title) .title(title)
.uri(uri) .uri(uri)
.description(description) .description(description)
@ -73,8 +72,7 @@ pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
.guid(guid) .guid(guid)
.podcast_id(parent_id) .podcast_id(parent_id)
.build() .build()
.unwrap() .unwrap())
)
} }
@ -278,9 +276,9 @@ mod tests {
let firstitem = channel.items().first().unwrap(); let firstitem = channel.items().first().unwrap();
let descr = "Audit your network with a couple of easy commands on Kali Linux. Chris \ 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 \ decides to blow off a little steam by attacking his IoT devices, Wes has the \
the scope on Equifax blaming open source &amp; the Beard just saved the \ scope on Equifax blaming open source &amp; the Beard just saved the show. \
show. Its a really packed episode!"; Its a really packed episode!";
let i = new_episode(&firstitem, 0).unwrap(); let i = new_episode(&firstitem, 0).unwrap();
assert_eq!(i.title(), Some("Hacking Devices with Kali Linux | LUP 214")); 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 channel = Channel::read_from(BufReader::new(file)).unwrap();
let firstitem = channel.items().iter().nth(9).unwrap(); let firstitem = channel.items().iter().nth(9).unwrap();
let descr = "This week we look at <a \ let descr = "This week we look at <a href=\"https://github.com/rust-lang/rfcs/pull/2094\" \
href=\"https://github.com/rust-lang/rfcs/pull/2094\" rel=\"noopener \ rel=\"noopener noreferrer\">RFC 2094</a> \"Non-lexical lifetimes\"";
noreferrer\">RFC 2094</a> \"Non-lexical lifetimes\"";
let i = new_episode(&firstitem, 0).unwrap(); let i = new_episode(&firstitem, 0).unwrap();
assert_eq!(i.title(), Some("Episode #9 - A Once in a Lifetime RFC")); 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 second = channel.items().iter().nth(8).unwrap();
let i2 = new_episode(&second, 0).unwrap(); let i2 = new_episode(&second, 0).unwrap();
let descr2 = "This week we look at <a href=\"https://github.com/rust-lang/rfcs/pull/2071\" \ let descr2 = "This week we look at <a \
rel=\"noopener noreferrer\">RFC 2071</a> \"Add impl Trait type alias and \ href=\"https://github.com/rust-lang/rfcs/pull/2071\" rel=\"noopener \
variable declarations\""; noreferrer\">RFC 2071</a> \"Add impl Trait type alias and variable \
declarations\"";
assert_eq!(i2.title(), Some("Episode #8 - An Existential Crisis")); assert_eq!(i2.title(), Some("Episode #8 - An Existential Crisis"));
assert_eq!( assert_eq!(
i2.uri(), i2.uri(),

View File

@ -111,7 +111,8 @@ pub fn replace_extra_spaces(s: &str) -> String {
s.lines() s.lines()
.map(|x| x.split_whitespace().collect::<Vec<_>>().join(" ")) .map(|x| x.split_whitespace().collect::<Vec<_>>().join(" "))
.filter(|x| !x.is_empty()) .filter(|x| !x.is_empty())
.collect::<Vec<_>>().join("\n") .collect::<Vec<_>>()
.join("\n")
} }
#[cfg(test)] #[cfg(test)]

View File

@ -60,7 +60,8 @@ fn download_into(dir: &str, file_title: &str, url: &str) -> Result<String> {
// Determine the file extension from the http content-type header. // Determine the file extension from the http content-type header.
fn get_ext(content: Option<ContentType>) -> Option<String> { fn get_ext(content: Option<ContentType>) -> Option<String> {
let cont = content.clone()?; let cont = content.clone()?;
content.and_then(|c| mime_guess::get_extensions(c.type_().as_ref(), c.subtype().as_ref())) content
.and_then(|c| mime_guess::get_extensions(c.type_().as_ref(), c.subtype().as_ref()))
.and_then(|c| { .and_then(|c| {
if c.contains(&cont.subtype().as_ref()) { if c.contains(&cont.subtype().as_ref()) {
Some(cont.subtype().as_ref().to_string()) Some(cont.subtype().as_ref().to_string())

View File

@ -46,7 +46,7 @@ impl Content {
self.podcasts.init(&self.stack); self.podcasts.init(&self.stack);
if self.podcasts.flowbox.get_children().is_empty() { if self.podcasts.flowbox.get_children().is_empty() {
self.stack.set_visible_child_name("empty"); self.stack.set_visible_child_name("empty");
return return;
} }
self.stack.set_visible_child_name("podcasts"); self.stack.set_visible_child_name("podcasts");
@ -165,7 +165,7 @@ impl UpdateView for ContentState<WidgetsView> {
let id = WidgetExt::get_name(&old).unwrap(); let id = WidgetExt::get_name(&old).unwrap();
let pd = dbqueries::get_podcast_from_id(id.parse::<i32>().unwrap()).unwrap(); let pd = dbqueries::get_podcast_from_id(id.parse::<i32>().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); self.content.replace_widget(pdw);
} }
} }
@ -178,8 +178,7 @@ impl ContentState<PodcastsView> {
content.podcasts.init(&content.stack); content.podcasts.init(&content.stack);
if content.podcasts.flowbox.get_children().is_empty() { if content.podcasts.flowbox.get_children().is_empty() {
content.stack.set_visible_child_name("empty"); content.stack.set_visible_child_name("empty");
return Err( return Err(ContentState {
ContentState{
content, content,
state: Empty {}, state: Empty {},
}); });