From b87c331b12da9268e4cd6fbaf00df7bb1e0bb766 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Mon, 12 Mar 2018 07:28:09 +0200 Subject: [PATCH] Make the itunes_resolver functions inlined. --- hammond-gtk/src/utils.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/hammond-gtk/src/utils.rs b/hammond-gtk/src/utils.rs index 7fa8682..b0a93fe 100644 --- a/hammond-gtk/src/utils.rs +++ b/hammond-gtk/src/utils.rs @@ -109,12 +109,14 @@ pub fn get_pixbuf_from_path(pd: &PodcastCoverQuery, size: u32) -> Result Result` pub fn itunes_to_rss(url: &str) -> Result { let id = itunes_id_from_url(url).ok_or_else(|| format_err!("Failed to find an Itunes ID."))?; lookup_id(id) } +#[inline] fn itunes_id_from_url(url: &str) -> Option { lazy_static! { static ref RE: Regex = Regex::new(r"/id([0-9]+)").unwrap(); @@ -126,6 +128,7 @@ fn itunes_id_from_url(url: &str) -> Option { foo.parse::().ok() } +#[inline] fn lookup_id(id: u32) -> Result { let url = format!("https://itunes.apple.com/lookup?id={}&entity=podcast", id); let req: Value = reqwest::get(&url)?.json()?; @@ -165,25 +168,20 @@ mod tests { fn test_itunes_to_rss() { let itunes_url = "https://itunes.apple.com/podcast/id1195206601"; let rss_url = String::from("http://feeds.feedburner.com/InterceptedWithJeremyScahill"); - assert_eq!(rss_url, itunes_to_rss(itunes_url).unwrap()); } #[test] fn test_itunes_id() { - let itunes_url = "https://itunes.apple.com/podcast/id1195206601"; let id = 1195206601; - + let itunes_url = "https://itunes.apple.com/podcast/id1195206601"; assert_eq!(id, itunes_id_from_url(itunes_url).unwrap()); } #[test] fn test_itunes_lookup_id() { let id = 1195206601; - - assert_eq!( - "http://feeds.feedburner.com/InterceptedWithJeremyScahill", - lookup_id(id).unwrap() - ); + let rss_url = "http://feeds.feedburner.com/InterceptedWithJeremyScahill"; + assert_eq!(rss_url, lookup_id(id).unwrap()); } }