rust_tdlib/types/
chats.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct Chats {
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 #[serde(default)]
16 total_count: i32,
17 #[serde(default)]
20 chat_ids: Vec<i64>,
21}
22
23impl RObject for Chats {
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 Chats {
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() -> ChatsBuilder {
39 let mut inner = Chats::default();
40 inner.extra = Some(Uuid::new_v4().to_string());
41
42 ChatsBuilder { inner }
43 }
44
45 pub fn total_count(&self) -> i32 {
46 self.total_count
47 }
48
49 pub fn chat_ids(&self) -> &Vec<i64> {
50 &self.chat_ids
51 }
52}
53
54#[doc(hidden)]
55pub struct ChatsBuilder {
56 inner: Chats,
57}
58
59#[deprecated]
60pub type RTDChatsBuilder = ChatsBuilder;
61
62impl ChatsBuilder {
63 pub fn build(&self) -> Chats {
64 self.inner.clone()
65 }
66
67 pub fn total_count(&mut self, total_count: i32) -> &mut Self {
68 self.inner.total_count = total_count;
69 self
70 }
71
72 pub fn chat_ids(&mut self, chat_ids: Vec<i64>) -> &mut Self {
73 self.inner.chat_ids = chat_ids;
74 self
75 }
76}
77
78impl AsRef<Chats> for Chats {
79 fn as_ref(&self) -> &Chats {
80 self
81 }
82}
83
84impl AsRef<Chats> for ChatsBuilder {
85 fn as_ref(&self) -> &Chats {
86 &self.inner
87 }
88}