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