From 874d33c1f4dd994365b71efe30d46ef9b6d624a0 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Sat, 23 Sep 2017 09:06:15 +0300 Subject: [PATCH] Setup of Rustfmt and rustfmt.toml config file. --- rustfmt.toml | 27 ++++++++++++++++++++++++++ src/cli.rs | 2 +- src/dbqueries.rs | 4 ++-- src/feedparser.rs | 49 +++++++++++++---------------------------------- src/index_feed.rs | 25 ++++++++++++------------ src/lib.rs | 12 +++++------- src/main.rs | 2 +- src/models.rs | 12 +++++------- 8 files changed, 66 insertions(+), 67 deletions(-) create mode 100644 rustfmt.toml diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..2173949 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,27 @@ +verbose = false +disable_all_formatting = false +skip_children = false +max_width = 100 +# error_on_line_overflow = true +error_on_line_overflow = false +wrap_comments = true +error_on_line_overflow_comments = true +tab_spaces = 4 +fn_call_width = 60 +newline_style = "Unix" +fn_call_style = "Block" +report_todo = "Never" +report_fixme = "Never" +reorder_extern_crates = true +reorder_extern_crates_in_group = true +reorder_imports = false +hard_tabs = false +spaces_within_parens = false +use_try_shorthand = false +write_mode = "Overwrite" +merge_derives = true +array_horizontal_layout_threshold = 5 +condense_wildcard_suffixes = true +# format_strings = true +chain_one_line_max = 60 +chain_split_single_child = false diff --git a/src/cli.rs b/src/cli.rs index 3527ddf..b6369b6 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -23,4 +23,4 @@ pub fn run() -> Result<()> { ::index_feed::foo(); Ok(()) -} \ No newline at end of file +} diff --git a/src/dbqueries.rs b/src/dbqueries.rs index ea0b59a..5243488 100644 --- a/src/dbqueries.rs +++ b/src/dbqueries.rs @@ -1,5 +1,5 @@ use diesel::prelude::*; -use models::{Podcast, Episode, Source}; +use models::{Episode, Podcast, Source}; pub fn get_sources(con: &SqliteConnection) -> QueryResult> { use schema::source::dsl::*; @@ -38,4 +38,4 @@ pub fn load_episode(con: &SqliteConnection, uri_: &str) -> QueryResult let ep = episode.filter(uri.eq(uri_)).get_result::(con); ep -} \ No newline at end of file +} diff --git a/src/feedparser.rs b/src/feedparser.rs index e0e7eb4..f20ec7f 100644 --- a/src/feedparser.rs +++ b/src/feedparser.rs @@ -4,7 +4,6 @@ use models; use errors::*; pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result { - let title = chan.title().to_owned(); let link = chan.link().to_owned(); @@ -28,7 +27,6 @@ pub fn parse_podcast(chan: &Channel, source_id: i32) -> Result(item: &'a Item, parent_id: i32) -> Result> { - let title = item.title(); let description = item.description(); @@ -72,9 +70,8 @@ pub fn parse_episode<'a>(item: &'a Item, parent_id: i32) -> Result 0, }; - let length = item.enclosure().map( - |x| x.length().parse().unwrap_or_default(), - ); + let length = item.enclosure() + .map(|x| x.length().parse().unwrap_or_default()); let foo = models::NewEpisode { title, @@ -140,9 +137,7 @@ mod tests { assert_eq!(pd.description, descr.to_string()); assert_eq!( pd.image_uri, - Some( - "http://michaeltunnell.com/images/linux-unplugged.jpg".to_string(), - ) + Some("http://michaeltunnell.com/images/linux-unplugged.jpg".to_string(),) ); } @@ -162,9 +157,7 @@ mod tests { assert_eq!(pd.description, descr.to_string()); assert_eq!( pd.image_uri, - Some( - "https://request-for-explanation.github.io/podcast/podcast.png".to_string(), - ) + Some("https://request-for-explanation.github.io/podcast/podcast.png".to_string(),) ); } @@ -191,9 +184,7 @@ mod tests { let descr2 = "This week on Intercepted: Jeremy gives an update on the aftermath of Blackwater’s 2007 massacre of Iraqi civilians. Intercept reporter Lee Fang lays out how a network of libertarian think tanks called the Atlas Network is insidiously shaping political infrastructure in Latin America. We speak with attorney and former Hugo Chavez adviser Eva Golinger about the Venezuela\'s political turmoil.And we hear Claudia Lizardo of the Caracas-based band, La Pequeña Revancha, talk about her music and hopes for Venezuela."; assert_eq!( i2.title, - Some( - "Atlas Golfed — U.S.-Backed Think Tanks Target Latin America", - ) + Some("Atlas Golfed — U.S.-Backed Think Tanks Target Latin America",) ); assert_eq!(i2.uri, Some("http://traffic.megaphone.fm/FL5331443769.mp3")); assert_eq!(i2.description, Some(descr2)); @@ -217,15 +208,11 @@ mod tests { assert_eq!( i.title, - Some( - "The Breakthrough: Hopelessness and Exploitation Inside Homes for Mentally Ill", - ) + Some("The Breakthrough: Hopelessness and Exploitation Inside Homes for Mentally Ill",) ); assert_eq!( i.uri, - Some( - "http://tracking.feedpress.it/link/10581/6726758/20170908-cliff-levy.mp3", - ) + Some("http://tracking.feedpress.it/link/10581/6726758/20170908-cliff-levy.mp3",) ); assert_eq!(i.description, Some(descr)); assert_eq!(i.length, Some(33396551)); @@ -253,9 +240,7 @@ mod tests { ); assert_eq!( i2.uri, - Some( - "http://tracking.feedpress.it/link/10581/6726759/16_JohnAllen-CRAFT.mp3", - ) + Some("http://tracking.feedpress.it/link/10581/6726759/16_JohnAllen-CRAFT.mp3",) ); assert_eq!(i2.description, Some(descr2)); assert_eq!(i2.length, Some(17964071)); @@ -281,9 +266,7 @@ mod tests { assert_eq!(i.title, Some("Hacking Devices with Kali Linux | LUP 214")); assert_eq!( i.uri, - Some( - "http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3", - ) + Some("http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0214.mp3",) ); assert_eq!(i.description, Some(descr)); assert_eq!(i.length, Some(46479789)); @@ -300,9 +283,7 @@ mod tests { assert_eq!(i2.title, Some("Gnome Does it Again | LUP 213")); assert_eq!( i2.uri, - Some( - "http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3", - ) + Some("http://www.podtrac.com/pts/redirect.mp3/traffic.libsyn.com/jnite/lup-0213.mp3",) ); assert_eq!(i2.description, Some(descr2)); assert_eq!(i2.length, Some(36544272)); @@ -331,9 +312,7 @@ mod tests { assert_eq!(i.length, Some(15077388)); assert_eq!( i.guid, - Some( - "https://request-for-explanation.github.io/podcast/ep9-a-once-in-a-lifetime-rfc/", - ) + Some("https://request-for-explanation.github.io/podcast/ep9-a-once-in-a-lifetime-rfc/",) ); assert_eq!(i.published_date, Some("Mon, 28 Aug 2017 15:00:00 PDT")); // Need to fix datetime parser first @@ -354,12 +333,10 @@ mod tests { assert_eq!(i2.length, Some(13713219)); assert_eq!( i2.guid, - Some( - "https://request-for-explanation.github.io/podcast/ep8-an-existential-crisis/", - ) + Some("https://request-for-explanation.github.io/podcast/ep8-an-existential-crisis/",) ); assert_eq!(i2.published_date, Some("Tue, 15 Aug 2017 17:00:00 PDT")); // Need to fix datetime parser first // assert_eq!(i.epoch, ); } -} \ No newline at end of file +} diff --git a/src/index_feed.rs b/src/index_feed.rs index 69cd58d..9b06ab1 100644 --- a/src/index_feed.rs +++ b/src/index_feed.rs @@ -6,7 +6,7 @@ use schema; use dbqueries; use feedparser; use errors::*; -use models::{NewSource, Source, Podcast, Episode}; +use models::{Episode, NewSource, Podcast, Source}; pub fn foo() { let inpt = vec![ @@ -42,9 +42,9 @@ fn insert_source(con: &SqliteConnection, url: &str) -> Result { // bar.save_changes::(con)?; } Err(_) => { - diesel::insert(&foo).into(schema::source::table).execute( - con, - )?; + diesel::insert(&foo) + .into(schema::source::table) + .execute(con)?; } } @@ -67,9 +67,9 @@ fn index_podcast( foo.save_changes::(con)?; } Err(_) => { - diesel::insert(&pd).into(schema::podcast::table).execute( - con, - )?; + diesel::insert(&pd) + .into(schema::podcast::table) + .execute(con)?; } } @@ -89,11 +89,11 @@ fn index_episode(con: &SqliteConnection, item: &rss::Item, parent: &Podcast) -> foo.set_length(ep.length); foo.set_epoch(ep.epoch); foo.save_changes::(con)?; - } + } Err(_) => { - diesel::insert(&ep).into(schema::episode::table).execute( - con, - )?; + diesel::insert(&ep) + .into(schema::episode::table) + .execute(con)?; } } @@ -122,7 +122,6 @@ pub fn index_loop(db: SqliteConnection) -> Result<()> { info!("{:#?}", pd); // info!("{:#?}", episodes); // info!("{:?}", chan); - } Ok(()) -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 744ace1..aafd1df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,10 +19,10 @@ extern crate diesel; #[macro_use] extern crate diesel_codegen; -extern crate xdg; +extern crate chrono; extern crate reqwest; extern crate rss; -extern crate chrono; +extern crate xdg; pub mod cli; pub mod schema; @@ -68,7 +68,7 @@ lazy_static!{ static ref HAMMOND_DATA: PathBuf = HAMMOND_XDG.create_data_directory(HAMMOND_XDG.get_data_home()).unwrap(); static ref HAMMOND_CONFIG: PathBuf = HAMMOND_XDG.create_config_directory(HAMMOND_XDG.get_config_home()).unwrap(); static ref HAMMOND_CACHE: PathBuf = HAMMOND_XDG.create_cache_directory(HAMMOND_XDG.get_cache_home()).unwrap(); - + static ref DB_PATH: PathBuf = { // Ensure that xdg_data is created. &HAMMOND_DATA; @@ -88,10 +88,8 @@ pub fn init() -> Result<()> { pub fn establish_connection() -> SqliteConnection { let database_url = DB_PATH.to_str().unwrap(); // let database_url = &String::from(".random/foo.db"); - SqliteConnection::establish(database_url).expect(&format!( - "Error connecting to {}", - database_url - )) + SqliteConnection::establish(database_url) + .expect(&format!("Error connecting to {}", database_url)) } #[cfg(test)] diff --git a/src/main.rs b/src/main.rs index e5f801e..02a118a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,4 +7,4 @@ extern crate hammond; use hammond::cli::run; -quick_main!(run); \ No newline at end of file +quick_main!(run); diff --git a/src/models.rs b/src/models.rs index 2af2075..fa784a7 100644 --- a/src/models.rs +++ b/src/models.rs @@ -7,8 +7,7 @@ use reqwest::header::{ETag, LastModified}; use schema::{episode, podcast, source}; use errors::*; -#[derive(Queryable, Identifiable, AsChangeset)] -#[derive(Associations)] +#[derive(Queryable, Identifiable, AsChangeset, Associations)] #[table_name = "episode"] #[belongs_to(Podcast, foreign_key = "podcast_id")] #[derive(Debug, Clone)] @@ -95,8 +94,7 @@ impl Episode { } } -#[derive(Queryable, Identifiable, AsChangeset)] -#[derive(Associations)] +#[derive(Queryable, Identifiable, AsChangeset, Associations)] #[belongs_to(Source, foreign_key = "source_id")] #[table_name = "podcast"] #[derive(Debug, Clone)] @@ -195,9 +193,9 @@ impl<'a> Source { Ok(chan) } - /// Extract Etag and LastModifier from req, and update self and the corresponding db row. + /// Extract Etag and LastModifier from req, and update self and the + /// corresponding db row. fn update_etag(&mut self, con: &SqliteConnection, req: &reqwest::Response) -> Result<()> { - let headers = req.headers(); debug!("{:#?}", headers); @@ -267,4 +265,4 @@ impl NewPodcast { let foo = ::feedparser::parse_podcast(&chan, parent.id())?; Ok(foo) } -} \ No newline at end of file +}