diff options
| author | njaremko | 2017-07-17 23:27:05 -0400 |
|---|---|---|
| committer | njaremko | 2017-07-17 23:27:05 -0400 |
| commit | 2b76588847e0455b5ddc30d62688d801b7cbe13f (patch) | |
| tree | 698519abad6faf5cff9ae6c9ebb48e3e75ad8143 /src | |
| parent | 80f4314bedc4ec6c727287000d3f3dd775b894f5 (diff) | |
| download | podcast-2b76588847e0455b5ddc30d62688d801b7cbe13f.tar.bz2 | |
Fix some linting warnings
Diffstat (limited to 'src')
| -rw-r--r-- | src/actions.rs | 32 | ||||
| -rw-r--r-- | src/main.rs | 12 | ||||
| -rw-r--r-- | src/structs.rs | 12 |
3 files changed, 27 insertions, 29 deletions
diff --git a/src/actions.rs b/src/actions.rs index 1319cd6..f6fb679 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -7,8 +7,8 @@ use std::io::{Read, Write}; use std::fs::{DirBuilder, File}; use rss::Channel; -pub fn list_episodes(state: State, search: &str) { - let re = Regex::new(&search).unwrap(); +pub fn list_episodes(state: &State, search: &str) { + let re = Regex::new(search).unwrap(); for podcast in state.subscriptions() { if re.is_match(&podcast.name) { println!("Episodes for {}:", &podcast.name); @@ -26,7 +26,7 @@ pub fn list_episodes(state: State, search: &str) { } } -pub fn update_rss(state: State) { +pub fn update_rss(state: &State) { let subs = state.subscriptions(); for sub in subs { let mut path = get_podcast_dir(); @@ -44,30 +44,29 @@ pub fn update_rss(state: State) { } } -pub fn list_subscriptions(state: State) { +pub fn list_subscriptions(state: &State) { for podcast in state.subscriptions() { println!("{}", podcast.name); } } -pub fn download_episode(state: State, p_search: &str, e_search: &str) { - let re_pod = Regex::new(&p_search).unwrap(); +pub fn download_episode(state: &State, p_search: &str, e_search: &str) { + let re_pod = Regex::new(p_search).unwrap(); let ep_num = e_search.parse::<usize>().unwrap(); for subscription in state.subscriptions() { if re_pod.is_match(&subscription.name) { let podcast = Podcast::from_url(&subscription.url).unwrap(); let episodes = podcast.episodes(); - match episodes[episodes.len() - ep_num].download(podcast.title()) { - Err(err) => println!("{}", err), - _ => (), + if let Err(err) = episodes[episodes.len() - ep_num].download(podcast.title()) { + println!("{}", err); } } } } -pub fn download_all(state: State, p_search: &str) { - let re_pod = Regex::new(&p_search).unwrap(); +pub fn download_all(state: &State, p_search: &str) { + let re_pod = Regex::new(p_search).unwrap(); for subscription in state.subscriptions() { if re_pod.is_match(&subscription.name) { @@ -77,8 +76,8 @@ pub fn download_all(state: State, p_search: &str) { } } -pub fn play_episode(state: State, p_search: &str, ep_num_string: &str) { - let re_pod = Regex::new(&p_search).unwrap(); +pub fn play_episode(state: &State, p_search: &str, ep_num_string: &str) { + let re_pod = Regex::new(p_search).unwrap(); let ep_num = ep_num_string.parse::<usize>().unwrap(); for subscription in state.subscriptions() { if re_pod.is_match(&subscription.name) { @@ -103,9 +102,10 @@ pub fn play_episode(state: State, p_search: &str, ep_num_string: &str) { path = get_podcast_dir(); path.push(podcast.title()); path.push(filename); - match path.exists() { - true => launch_mpv(path.to_str().unwrap()), - false => launch_mpv(episode.url().unwrap()), + if path.exists() { + launch_mpv(path.to_str().unwrap()); + } else { + launch_mpv(episode.url().unwrap()); } } } diff --git a/src/main.rs b/src/main.rs index 4134edb..0eab682 100644 --- a/src/main.rs +++ b/src/main.rs @@ -87,22 +87,22 @@ fn main() { let download_matches = matches.subcommand_matches("download").unwrap(); let podcast = download_matches.value_of("PODCAST").unwrap(); match download_matches.value_of("EPISODE") { - Some(ep) => download_episode(state, podcast, ep), - None => download_all(state, podcast), + Some(ep) => download_episode(&state, podcast, ep), + None => download_all(&state, podcast), } } Some("list") => { let list_matches = matches.subcommand_matches("list").unwrap(); match list_matches.value_of("PODCAST") { - Some(regex) => list_episodes(state, regex), - None => list_subscriptions(state), + Some(regex) => list_episodes(&state, regex), + None => list_subscriptions(&state), } } Some("play") => { let play_matches = matches.subcommand_matches("play").unwrap(); let podcast = play_matches.value_of("PODCAST").unwrap(); let episode = play_matches.value_of("EPISODE").unwrap(); - play_episode(state, podcast, episode); + play_episode(&state, podcast, episode); } Some("subscribe") => { state.subscribe( @@ -114,7 +114,7 @@ fn main() { ) } Some("search") => (), - Some("update") => update_rss(state), + Some("update") => update_rss(&state), _ => (), } } diff --git a/src/structs.rs b/src/structs.rs index 2546139..923a0b1 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -41,11 +41,10 @@ impl State { url: String::from(url), }); } - match self.save() { - Err(err) => println!("{}", err), - _ => (), + if let Err(err) = self.save() { + println!("{}", err); } - update_rss(self.clone()); + update_rss(&self.clone()); } pub fn subscriptions(&self) -> Vec<Subscription> { @@ -115,9 +114,8 @@ impl Podcast { for ep in self.episodes() { if let Some(ep_title) = ep.title() { if !downloaded.contains(ep_title) { - match ep.download(self.title()) { - Err(err) => println!("{}", err), - _ => (), + if let Err(err) = ep.download(self.title()) { + println!("{}", err); } } } |
