cargo fmt

This commit is contained in:
Jordan Petridis 2018-10-23 13:22:35 +03:00
parent c6aa90db3e
commit 990d830f24
No known key found for this signature in database
GPG Key ID: E8523968931763BE
16 changed files with 75 additions and 72 deletions

View File

@ -93,5 +93,4 @@ rustfmt:
script:
- rustc -Vv && cargo -Vv
- cargo fmt --version
- cargo fmt --all -- --check
allow_failure: true
- cargo fmt --all -- --check

View File

@ -110,7 +110,8 @@ pub fn get_episode_widget_from_rowid(ep_id: i32) -> Result<EpisodeWidgetModel, D
episodes
.select((
rowid, title, uri, local_uri, epoch, length, duration, played, show_id,
)).filter(rowid.eq(ep_id))
))
.filter(rowid.eq(ep_id))
.get_result::<EpisodeWidgetModel>(&con)
.map_err(From::from)
}

View File

@ -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,

View File

@ -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());

View File

@ -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)

View File

@ -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()
};

View File

@ -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<Body>) -> Result<Self, DataError> {
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<Item = Response<Body>, 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<Body>) -> impl Future<Item = Channel, Error = DataError> + Send {
fn response_to_channel(
res: Response<Body>,
) -> impl Future<Item = Channel, Error = DataError> + Send {
res.into_body()
.concat2()
.map(|x| x.into_iter())

View File

@ -42,7 +42,8 @@ pub fn import_to_db<R: Read>(reader: R) -> Result<Vec<Source>, reader::Error> {
}
s.ok()
}).collect();
})
.collect();
Ok(feeds)
}
@ -91,7 +92,8 @@ pub fn extract_sources<R: Read>(reader: R) -> Result<HashSet<Opml>, reader::Erro
}
Err(err) => Err(err),
_ => Ok(()),
}).collect::<Result<Vec<_>, reader::Error>>()?;
})
.collect::<Result<Vec<_>, reader::Error>>()?;
Ok(list)
}

View File

@ -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<HttpsConnector<HttpConnector>>;
/// 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<Item = (), Error = ()> + 'a
pub fn pipeline<'a, S>(sources: S, client: HttpsClient) -> impl Future<Item = (), Error = ()> + 'a
where
S: Stream<Item = Source, Error = DataError> + Send + 'a,
{

View File

@ -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))

View File

@ -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;

View File

@ -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,

View File

@ -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;

View File

@ -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 {

View File

@ -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);
}

View File

@ -4,4 +4,3 @@ newline_style = "Unix"
format_strings = true
normalize_comments = true
use_field_init_shorthand = true
edition = "Edition2018"