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 100
use chrono::{DateTime, Local}; use serde::Deserialize; mod deser; #[derive(Deserialize, Debug, PartialEq)] pub struct Feed { pub title: Text, pub subtitle: Option<Text>, pub updated: Timestamp, pub id: String, #[serde(rename = "link", default)] pub links: Vec<Link>, pub rights: Option<String>, #[serde(rename = "author", default)] pub authors: Vec<Person>, #[serde(rename = "contributor", default)] pub contributors: Vec<Person>, #[serde(rename = "category", default)] pub categories: Vec<Category>, #[serde(rename = "entry", default)] pub entries: Vec<Entry>, } #[derive(Deserialize, Debug, PartialEq)] pub struct Entry { pub title: Text, #[serde(rename = "link", default)] pub links: Vec<Link>, pub id: String, #[serde(rename = "author", default)] pub authors: Vec<Person>, #[serde(rename = "contributor", default)] pub contributors: Vec<Person>, #[serde(rename = "category", default)] pub categories: Vec<Category>, pub updated: Timestamp, pub published: Option<Timestamp>, pub summary: Option<Text>, pub content: Option<Text>, } #[derive(Deserialize, Debug, PartialEq)] pub struct Text { #[serde(rename = "$value")] pub content: String, #[serde(rename = "type", default = "Text::default_type")] pub ty: String, } #[derive(Deserialize, Debug, PartialEq)] pub struct Person { pub name: String, #[serde(rename = "uri")] pub url: Option<String>, pub email: Option<String>, } #[derive(Deserialize, Debug, PartialEq)] pub struct Link { pub rel: Option<String>, #[serde(rename = "type")] pub ty: Option<String>, pub href: String, } #[derive(Deserialize, Debug, PartialEq)] pub struct Category { pub term: String, pub scheme: Option<String>, pub label: Option<String>, } #[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 } } impl Text { fn default_type() -> String { "text".to_string() } }