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,19 +62,17 @@ 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) .length(length)
.length(length) .published_date(pub_date)
.published_date(pub_date) .epoch(epoch)
.epoch(epoch) .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

@ -109,9 +109,10 @@ pub fn url_cleaner(s: &str) -> String {
// TODO: Docs // TODO: Docs
pub fn replace_extra_spaces(s: &str) -> String { 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)]
@ -151,7 +152,7 @@ mod tests {
.unwrap() .unwrap()
.into_episode(&con) .into_episode(&con)
.unwrap(); .unwrap();
let mut ep1 = dbqueries::get_episode_from_uri(&con, "foo_bar").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(); let mut ep2 = dbqueries::get_episode_from_uri(&con, "bar_baz").unwrap();
ep1.set_local_uri(Some(valid_path.to_str().unwrap())); ep1.set_local_uri(Some(valid_path.to_str().unwrap()));

View File

@ -60,15 +60,16 @@ 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| { .and_then(|c| mime_guess::get_extensions(c.type_().as_ref(), c.subtype().as_ref()))
if c.contains(&cont.subtype().as_ref()) { .and_then(|c| {
Some(cont.subtype().as_ref().to_string()) if c.contains(&cont.subtype().as_ref()) {
} else { Some(cont.subtype().as_ref().to_string())
Some(c.first().unwrap().to_string()) } else {
} Some(c.first().unwrap().to_string())
}) }
} })
}
// TODO: Write unit-tests. // TODO: Write unit-tests.
/// 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.

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");
@ -100,9 +100,9 @@ impl Into<ContentState<PodcastsView>> for ContentState<Empty> {
fn into(self) -> ContentState<PodcastsView> { fn into(self) -> ContentState<PodcastsView> {
self.content.stack.set_visible_child_name("podcasts"); self.content.stack.set_visible_child_name("podcasts");
ContentState{ ContentState {
content: self.content, content: self.content,
state: PodcastsView{}, state: PodcastsView {},
} }
} }
} }
@ -114,9 +114,9 @@ impl UpdateView for ContentState<Empty> {
impl Into<ContentState<Empty>> for ContentState<PodcastsView> { impl Into<ContentState<Empty>> for ContentState<PodcastsView> {
fn into(self) -> ContentState<Empty> { fn into(self) -> ContentState<Empty> {
self.content.stack.set_visible_child_name("empty"); self.content.stack.set_visible_child_name("empty");
ContentState{ ContentState {
content: self.content, content: self.content,
state: Empty{}, state: Empty {},
} }
} }
} }
@ -125,9 +125,9 @@ impl Into<ContentState<WidgetsView>> for ContentState<PodcastsView> {
fn into(self) -> ContentState<WidgetsView> { fn into(self) -> ContentState<WidgetsView> {
self.content.stack.set_visible_child_name("widget"); self.content.stack.set_visible_child_name("widget");
ContentState{ ContentState {
content: self.content, content: self.content,
state: WidgetsView{}, state: WidgetsView {},
} }
} }
} }
@ -142,9 +142,9 @@ impl UpdateView for ContentState<PodcastsView> {
impl Into<ContentState<PodcastsView>> for ContentState<WidgetsView> { impl Into<ContentState<PodcastsView>> for ContentState<WidgetsView> {
fn into(self) -> ContentState<PodcastsView> { fn into(self) -> ContentState<PodcastsView> {
self.content.stack.set_visible_child_name("podcasts"); self.content.stack.set_visible_child_name("podcasts");
ContentState{ ContentState {
content: self.content, content: self.content,
state: PodcastsView{}, state: PodcastsView {},
} }
} }
} }
@ -152,9 +152,9 @@ impl Into<ContentState<PodcastsView>> for ContentState<WidgetsView> {
impl Into<ContentState<Empty>> for ContentState<WidgetsView> { impl Into<ContentState<Empty>> for ContentState<WidgetsView> {
fn into(self) -> ContentState<Empty> { fn into(self) -> ContentState<Empty> {
self.content.stack.set_visible_child_name("empty"); self.content.stack.set_visible_child_name("empty");
ContentState{ ContentState {
content: self.content, content: self.content,
state: Empty{}, state: Empty {},
} }
} }
} }
@ -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,17 +178,16 @@ 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{}, });
});
} }
content.stack.set_visible_child_name("podcasts"); content.stack.set_visible_child_name("podcasts");
Ok(ContentState { Ok(ContentState {
content, content,
state: PodcastsView{}, state: PodcastsView {},
}) })
} }

View File

@ -90,7 +90,7 @@ impl EpisodeWidget {
// let mut text = text.clone(); // let mut text = text.clone();
// html_to_markup(&mut text); // html_to_markup(&mut text);
// description.set_markup(&text) // description.set_markup(&text)
let plain_text = strip_html_tags(&text).join(" "); let plain_text = strip_html_tags(&text).join(" ");
// TODO: handle unwrap // TODO: handle unwrap
let buff = description.get_buffer().unwrap(); let buff = description.get_buffer().unwrap();