rust_tdlib/types/
page_block_list_item.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Describes an item of a list page block
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct PageBlockListItem {
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    /// Item label
14
15    #[serde(default)]
16    label: String,
17    /// Item blocks
18
19    #[serde(default)]
20    page_blocks: Vec<PageBlock>,
21}
22
23impl RObject for PageBlockListItem {
24    #[doc(hidden)]
25    fn extra(&self) -> Option<&str> {
26        self.extra.as_deref()
27    }
28    #[doc(hidden)]
29    fn client_id(&self) -> Option<i32> {
30        self.client_id
31    }
32}
33
34impl PageBlockListItem {
35    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
36        Ok(serde_json::from_str(json.as_ref())?)
37    }
38    pub fn builder() -> PageBlockListItemBuilder {
39        let mut inner = PageBlockListItem::default();
40        inner.extra = Some(Uuid::new_v4().to_string());
41
42        PageBlockListItemBuilder { inner }
43    }
44
45    pub fn label(&self) -> &String {
46        &self.label
47    }
48
49    pub fn page_blocks(&self) -> &Vec<PageBlock> {
50        &self.page_blocks
51    }
52}
53
54#[doc(hidden)]
55pub struct PageBlockListItemBuilder {
56    inner: PageBlockListItem,
57}
58
59#[deprecated]
60pub type RTDPageBlockListItemBuilder = PageBlockListItemBuilder;
61
62impl PageBlockListItemBuilder {
63    pub fn build(&self) -> PageBlockListItem {
64        self.inner.clone()
65    }
66
67    pub fn label<T: AsRef<str>>(&mut self, label: T) -> &mut Self {
68        self.inner.label = label.as_ref().to_string();
69        self
70    }
71
72    pub fn page_blocks(&mut self, page_blocks: Vec<PageBlock>) -> &mut Self {
73        self.inner.page_blocks = page_blocks;
74        self
75    }
76}
77
78impl AsRef<PageBlockListItem> for PageBlockListItem {
79    fn as_ref(&self) -> &PageBlockListItem {
80        self
81    }
82}
83
84impl AsRef<PageBlockListItem> for PageBlockListItemBuilder {
85    fn as_ref(&self) -> &PageBlockListItem {
86        &self.inner
87    }
88}