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