rtdlib/types/
chat_position.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Describes a position of a chat in a chat list
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct ChatPosition {
12  #[doc(hidden)]
13  #[serde(rename(serialize = "@type", deserialize = "@type"))]
14  td_name: String,
15  #[doc(hidden)]
16  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17  extra: Option<String>,
18  /// The chat list
19  list: ChatList,
20  /// A parameter used to determine order of the chat in the chat list. Chats must be sorted by the pair (order, chat.id) in descending order
21  #[serde(deserialize_with = "serde_aux::field_attributes::deserialize_number_from_string")] order: isize,
22  /// True, if the chat is pinned in the chat list
23  is_pinned: bool,
24  /// Source of the chat in the chat list; may be null
25  source: Option<ChatSource>,
26  
27}
28
29impl RObject for ChatPosition {
30  #[doc(hidden)] fn td_name(&self) -> &'static str { "chatPosition" }
31  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
32  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
33}
34
35
36
37impl ChatPosition {
38  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
39  pub fn builder() -> RTDChatPositionBuilder {
40    let mut inner = ChatPosition::default();
41    inner.td_name = "chatPosition".to_string();
42    inner.extra = Some(Uuid::new_v4().to_string());
43    RTDChatPositionBuilder { inner }
44  }
45
46  pub fn list(&self) -> &ChatList { &self.list }
47
48  pub fn order(&self) -> isize { self.order }
49
50  pub fn is_pinned(&self) -> bool { self.is_pinned }
51
52  pub fn source(&self) -> &Option<ChatSource> { &self.source }
53
54}
55
56#[doc(hidden)]
57pub struct RTDChatPositionBuilder {
58  inner: ChatPosition
59}
60
61impl RTDChatPositionBuilder {
62  pub fn build(&self) -> ChatPosition { self.inner.clone() }
63
64   
65  pub fn list<T: AsRef<ChatList>>(&mut self, list: T) -> &mut Self {
66    self.inner.list = list.as_ref().clone();
67    self
68  }
69
70   
71  pub fn order(&mut self, order: isize) -> &mut Self {
72    self.inner.order = order;
73    self
74  }
75
76   
77  pub fn is_pinned(&mut self, is_pinned: bool) -> &mut Self {
78    self.inner.is_pinned = is_pinned;
79    self
80  }
81
82   
83  pub fn source<T: AsRef<ChatSource>>(&mut self, source: T) -> &mut Self {
84    self.inner.source = Some(source.as_ref().clone());
85    self
86  }
87
88}
89
90impl AsRef<ChatPosition> for ChatPosition {
91  fn as_ref(&self) -> &ChatPosition { self }
92}
93
94impl AsRef<ChatPosition> for RTDChatPositionBuilder {
95  fn as_ref(&self) -> &ChatPosition { &self.inner }
96}
97
98
99