1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
use chrono::{DateTime, Local}; use serde::Deserialize; mod deser; #[derive(Debug, PartialEq, Deserialize)] pub struct Rss { pub channel: Channel, } #[derive(Debug, PartialEq, Deserialize)] pub struct Channel { pub title: String, pub description: HtmlEncoded, pub language: Option<String>, pub copyright: Option<String>, #[serde(rename = "managingEditor")] pub managing_editor: Option<String>, #[serde(rename = "webMaster")] pub web_master: Option<String>, #[serde(rename = "pubDate")] pub pub_date: Option<Timestamp>, #[serde(rename = "lastBuildDate")] pub last_build_date: Option<Timestamp>, pub category: Option<Vec<String>>, pub generator: Option<String>, pub ttl: Option<usize>, #[serde(rename = "item")] pub items: Vec<Item>, } #[derive(Debug, PartialEq, Deserialize)] pub struct Item { pub title: Option<String>, pub link: Option<String>, pub author: Option<String>, pub category: Option<Vec<String>>, pub comments: Option<String>, pub guid: Option<Guid>, pub description: Option<HtmlEncoded>, #[serde(rename = "pubDate")] pub pub_date: Option<Timestamp>, } #[derive(Debug, PartialEq, Deserialize)] pub struct Guid { #[serde(default = "Guid::default_perma", rename = "isPermalink")] pub is_permalink: bool, #[serde(rename = "$value")] pub link: String, } impl Guid { fn default_perma() -> bool { true } } #[derive(PartialEq, Debug)] pub struct Timestamp { pub(crate) datetime: DateTime<Local>, } impl std::ops::Deref for Timestamp { type Target = DateTime<Local>; fn deref(&self) -> &DateTime<Local> { &self.datetime } } impl Into<DateTime<Local>> for Timestamp { fn into(self) -> DateTime<Local> { self.datetime } } #[derive(PartialEq, Debug)] pub struct HtmlEncoded(pub(crate) String); impl std::ops::Deref for HtmlEncoded { type Target = str; fn deref(&self) -> &str { self.0.deref() } } impl Into<String> for HtmlEncoded { fn into(self) -> String { self.0 } }