rust_tdlib/types/
set_chat_location.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Changes the location of a chat. Available only for some location-based supergroups, use supergroupFullInfo.can_set_location to check whether the method is allowed to use
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct SetChatLocation {
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    /// Chat identifier
14
15    #[serde(default)]
16    chat_id: i64,
17    /// New location for the chat; must be valid and not null
18    location: ChatLocation,
19
20    #[serde(rename(serialize = "@type"))]
21    td_type: String,
22}
23
24impl RObject for SetChatLocation {
25    #[doc(hidden)]
26    fn extra(&self) -> Option<&str> {
27        self.extra.as_deref()
28    }
29    #[doc(hidden)]
30    fn client_id(&self) -> Option<i32> {
31        self.client_id
32    }
33}
34
35impl RFunction for SetChatLocation {}
36
37impl SetChatLocation {
38    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
39        Ok(serde_json::from_str(json.as_ref())?)
40    }
41    pub fn builder() -> SetChatLocationBuilder {
42        let mut inner = SetChatLocation::default();
43        inner.extra = Some(Uuid::new_v4().to_string());
44
45        inner.td_type = "setChatLocation".to_string();
46
47        SetChatLocationBuilder { inner }
48    }
49
50    pub fn chat_id(&self) -> i64 {
51        self.chat_id
52    }
53
54    pub fn location(&self) -> &ChatLocation {
55        &self.location
56    }
57}
58
59#[doc(hidden)]
60pub struct SetChatLocationBuilder {
61    inner: SetChatLocation,
62}
63
64#[deprecated]
65pub type RTDSetChatLocationBuilder = SetChatLocationBuilder;
66
67impl SetChatLocationBuilder {
68    pub fn build(&self) -> SetChatLocation {
69        self.inner.clone()
70    }
71
72    pub fn chat_id(&mut self, chat_id: i64) -> &mut Self {
73        self.inner.chat_id = chat_id;
74        self
75    }
76
77    pub fn location<T: AsRef<ChatLocation>>(&mut self, location: T) -> &mut Self {
78        self.inner.location = location.as_ref().clone();
79        self
80    }
81}
82
83impl AsRef<SetChatLocation> for SetChatLocation {
84    fn as_ref(&self) -> &SetChatLocation {
85        self
86    }
87}
88
89impl AsRef<SetChatLocation> for SetChatLocationBuilder {
90    fn as_ref(&self) -> &SetChatLocation {
91        &self.inner
92    }
93}