From 52cbe677568decaca6d2ac6914e47809dbb9fbbb Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 3 Apr 2018 20:05:00 +0300 Subject: [PATCH] NewEpisode: refactor another if else statement and document it. --- hammond-data/src/models/new_episode.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/hammond-data/src/models/new_episode.rs b/hammond-data/src/models/new_episode.rs index 3b25fb5..64c2fa8 100644 --- a/hammond-data/src/models/new_episode.rs +++ b/hammond-data/src/models/new_episode.rs @@ -196,11 +196,14 @@ impl NewEpisodeMinimal { let title = item.title().unwrap().trim().to_owned(); let guid = item.guid().map(|s| s.value().trim().to_owned()); - let uri = if let Some(url) = item.enclosure().map(|s| url_cleaner(s.url())) { - Some(url) - } else if item.link().is_some() { - item.link().map(|s| url_cleaner(s)) - } else { + let uri = item.enclosure() + .map(|s| url_cleaner(s.url())) + // Fallback to Rss.Item.link if enclosure is None. + .or_else(|| item.link().map(|s| url_cleaner(s))); + + // If url is still None return an Error as this behaviour is + // compliant with the RSS Spec. + if uri.is_none() { let err = DataError::ParseEpisodeError { reason: "No url specified for the item.".into(), parent_id,