rust_tdlib/types/
page_block_related_article.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Contains information about a related article
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct PageBlockRelatedArticle {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// Related article URL
14
15    #[serde(default)]
16    url: String,
17    /// Article title; may be empty
18
19    #[serde(default)]
20    title: String,
21    /// Contains information about a related article
22
23    #[serde(default)]
24    description: String,
25    /// Article photo; may be null
26    photo: Option<Photo>,
27    /// Article author; may be empty
28
29    #[serde(default)]
30    author: String,
31    /// Point in time (Unix timestamp) when the article was published; 0 if unknown
32
33    #[serde(default)]
34    publish_date: i32,
35}
36
37impl RObject for PageBlockRelatedArticle {
38    #[doc(hidden)]
39    fn extra(&self) -> Option<&str> {
40        self.extra.as_deref()
41    }
42    #[doc(hidden)]
43    fn client_id(&self) -> Option<i32> {
44        self.client_id
45    }
46}
47
48impl PageBlockRelatedArticle {
49    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
50        Ok(serde_json::from_str(json.as_ref())?)
51    }
52    pub fn builder() -> PageBlockRelatedArticleBuilder {
53        let mut inner = PageBlockRelatedArticle::default();
54        inner.extra = Some(Uuid::new_v4().to_string());
55
56        PageBlockRelatedArticleBuilder { inner }
57    }
58
59    pub fn url(&self) -> &String {
60        &self.url
61    }
62
63    pub fn title(&self) -> &String {
64        &self.title
65    }
66
67    pub fn description(&self) -> &String {
68        &self.description
69    }
70
71    pub fn photo(&self) -> &Option<Photo> {
72        &self.photo
73    }
74
75    pub fn author(&self) -> &String {
76        &self.author
77    }
78
79    pub fn publish_date(&self) -> i32 {
80        self.publish_date
81    }
82}
83
84#[doc(hidden)]
85pub struct PageBlockRelatedArticleBuilder {
86    inner: PageBlockRelatedArticle,
87}
88
89#[deprecated]
90pub type RTDPageBlockRelatedArticleBuilder = PageBlockRelatedArticleBuilder;
91
92impl PageBlockRelatedArticleBuilder {
93    pub fn build(&self) -> PageBlockRelatedArticle {
94        self.inner.clone()
95    }
96
97    pub fn url<T: AsRef<str>>(&mut self, url: T) -> &mut Self {
98        self.inner.url = url.as_ref().to_string();
99        self
100    }
101
102    pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
103        self.inner.title = title.as_ref().to_string();
104        self
105    }
106
107    pub fn description<T: AsRef<str>>(&mut self, description: T) -> &mut Self {
108        self.inner.description = description.as_ref().to_string();
109        self
110    }
111
112    pub fn photo<T: AsRef<Photo>>(&mut self, photo: T) -> &mut Self {
113        self.inner.photo = Some(photo.as_ref().clone());
114        self
115    }
116
117    pub fn author<T: AsRef<str>>(&mut self, author: T) -> &mut Self {
118        self.inner.author = author.as_ref().to_string();
119        self
120    }
121
122    pub fn publish_date(&mut self, publish_date: i32) -> &mut Self {
123        self.inner.publish_date = publish_date;
124        self
125    }
126}
127
128impl AsRef<PageBlockRelatedArticle> for PageBlockRelatedArticle {
129    fn as_ref(&self) -> &PageBlockRelatedArticle {
130        self
131    }
132}
133
134impl AsRef<PageBlockRelatedArticle> for PageBlockRelatedArticleBuilder {
135    fn as_ref(&self) -> &PageBlockRelatedArticle {
136        &self.inner
137    }
138}