rust_tdlib/types/
set_location.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Changes the location of the current user. Needs to be called if GetOption("is_location_visible") is true and location changes for more than 1 kilometer
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct SetLocation {
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    /// The new location of the user
14    location: Location,
15
16    #[serde(rename(serialize = "@type"))]
17    td_type: String,
18}
19
20impl RObject for SetLocation {
21    #[doc(hidden)]
22    fn extra(&self) -> Option<&str> {
23        self.extra.as_deref()
24    }
25    #[doc(hidden)]
26    fn client_id(&self) -> Option<i32> {
27        self.client_id
28    }
29}
30
31impl RFunction for SetLocation {}
32
33impl SetLocation {
34    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
35        Ok(serde_json::from_str(json.as_ref())?)
36    }
37    pub fn builder() -> SetLocationBuilder {
38        let mut inner = SetLocation::default();
39        inner.extra = Some(Uuid::new_v4().to_string());
40
41        inner.td_type = "setLocation".to_string();
42
43        SetLocationBuilder { inner }
44    }
45
46    pub fn location(&self) -> &Location {
47        &self.location
48    }
49}
50
51#[doc(hidden)]
52pub struct SetLocationBuilder {
53    inner: SetLocation,
54}
55
56#[deprecated]
57pub type RTDSetLocationBuilder = SetLocationBuilder;
58
59impl SetLocationBuilder {
60    pub fn build(&self) -> SetLocation {
61        self.inner.clone()
62    }
63
64    pub fn location<T: AsRef<Location>>(&mut self, location: T) -> &mut Self {
65        self.inner.location = location.as_ref().clone();
66        self
67    }
68}
69
70impl AsRef<SetLocation> for SetLocation {
71    fn as_ref(&self) -> &SetLocation {
72        self
73    }
74}
75
76impl AsRef<SetLocation> for SetLocationBuilder {
77    fn as_ref(&self) -> &SetLocation {
78        &self.inner
79    }
80}