From 9775a32a5f2f5c8a164aad0c8db1a66041f204ac Mon Sep 17 00:00:00 2001 From: Alexandre Lehmann Holzhey Date: Mon, 27 May 2024 19:05:53 +0200 Subject: [PATCH] extract into get_warning --- src/main.rs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index 2e3c676..0349cff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,13 +25,18 @@ struct Item { struct Warning { title: String, content: String, + link: String, } impl Display for Warning { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let mut c = self.content.clone(); c.truncate(150); - write!(f, "** {} **\n{}\n-------------", self.title, c) + write!( + f, + "** {} **\n{}\n{}\n-------------", + self.title, self.link, c + ) } } @@ -46,23 +51,26 @@ fn main() -> Result<(), Box> { fn get_warnings(doc: Rss) -> Result, Box> { let mut warnings = Vec::new(); for item in doc.channel.item { - let title = item.title; - let mut desc = "(failed to parse description)"; + warnings.push(get_warning(item)); + } + Ok(warnings) +} - let start = item.description.find("
").unwrap_or(0);
-        let finish = item.description.find("
").unwrap_or(desc.len()); - dbg!(start, finish); - if start != 0 && finish != desc.len() { - desc = &item.description[start..finish]; - } +fn get_warning(item: Item) -> Warning { + let mut desc = "(failed to parse description)"; - warnings.push(Warning { - title: title.to_string(), - content: desc.to_string(), - }) + let start = item.description.find("
").unwrap_or(0);
+    let finish = item.description.find("
").unwrap_or(desc.len()); + dbg!(start, finish); + if start != 0 && finish != desc.len() { + desc = &item.description[start..finish]; } - Ok(warnings) + Warning { + title: item.title.to_string(), + content: desc.to_string(), + link: item.link, + } } fn get_feed() -> Result> {