rust_tdlib/types/
statistical_graph.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7/// Describes a statistical graph
8pub trait TDStatisticalGraph: Debug + RObject {}
9
10/// Describes a statistical graph
11#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum StatisticalGraph {
14    #[doc(hidden)]
15    #[default]
16    _Default,
17    /// Loads an asynchronous or a zoomed in statistical graph
18    #[serde(rename = "getStatisticalGraph")]
19    GetStatisticalGraph(GetStatisticalGraph),
20    /// The graph data to be asynchronously loaded through getStatisticalGraph
21    #[serde(rename = "statisticalGraphAsync")]
22    Async(StatisticalGraphAsync),
23    /// A graph data
24    #[serde(rename = "statisticalGraphData")]
25    Data(StatisticalGraphData),
26    /// An error message to be shown to the user instead of the graph
27    #[serde(rename = "statisticalGraphError")]
28    Error(StatisticalGraphError),
29}
30
31impl RObject for StatisticalGraph {
32    #[doc(hidden)]
33    fn extra(&self) -> Option<&str> {
34        match self {
35            StatisticalGraph::GetStatisticalGraph(t) => t.extra(),
36            StatisticalGraph::Async(t) => t.extra(),
37            StatisticalGraph::Data(t) => t.extra(),
38            StatisticalGraph::Error(t) => t.extra(),
39
40            _ => None,
41        }
42    }
43    #[doc(hidden)]
44    fn client_id(&self) -> Option<i32> {
45        match self {
46            StatisticalGraph::GetStatisticalGraph(t) => t.client_id(),
47            StatisticalGraph::Async(t) => t.client_id(),
48            StatisticalGraph::Data(t) => t.client_id(),
49            StatisticalGraph::Error(t) => t.client_id(),
50
51            _ => None,
52        }
53    }
54}
55
56impl StatisticalGraph {
57    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
58        Ok(serde_json::from_str(json.as_ref())?)
59    }
60    #[doc(hidden)]
61    pub fn _is_default(&self) -> bool {
62        matches!(self, StatisticalGraph::_Default)
63    }
64}
65
66impl AsRef<StatisticalGraph> for StatisticalGraph {
67    fn as_ref(&self) -> &StatisticalGraph {
68        self
69    }
70}
71
72/// The graph data to be asynchronously loaded through getStatisticalGraph
73#[derive(Debug, Clone, Default, Serialize, Deserialize)]
74pub struct StatisticalGraphAsync {
75    #[doc(hidden)]
76    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
77    extra: Option<String>,
78    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
79    client_id: Option<i32>,
80    /// The token to use for data loading
81
82    #[serde(default)]
83    token: String,
84}
85
86impl RObject for StatisticalGraphAsync {
87    #[doc(hidden)]
88    fn extra(&self) -> Option<&str> {
89        self.extra.as_deref()
90    }
91    #[doc(hidden)]
92    fn client_id(&self) -> Option<i32> {
93        self.client_id
94    }
95}
96
97impl TDStatisticalGraph for StatisticalGraphAsync {}
98
99impl StatisticalGraphAsync {
100    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
101        Ok(serde_json::from_str(json.as_ref())?)
102    }
103    pub fn builder() -> StatisticalGraphAsyncBuilder {
104        let mut inner = StatisticalGraphAsync::default();
105        inner.extra = Some(Uuid::new_v4().to_string());
106
107        StatisticalGraphAsyncBuilder { inner }
108    }
109
110    pub fn token(&self) -> &String {
111        &self.token
112    }
113}
114
115#[doc(hidden)]
116pub struct StatisticalGraphAsyncBuilder {
117    inner: StatisticalGraphAsync,
118}
119
120#[deprecated]
121pub type RTDStatisticalGraphAsyncBuilder = StatisticalGraphAsyncBuilder;
122
123impl StatisticalGraphAsyncBuilder {
124    pub fn build(&self) -> StatisticalGraphAsync {
125        self.inner.clone()
126    }
127
128    pub fn token<T: AsRef<str>>(&mut self, token: T) -> &mut Self {
129        self.inner.token = token.as_ref().to_string();
130        self
131    }
132}
133
134impl AsRef<StatisticalGraphAsync> for StatisticalGraphAsync {
135    fn as_ref(&self) -> &StatisticalGraphAsync {
136        self
137    }
138}
139
140impl AsRef<StatisticalGraphAsync> for StatisticalGraphAsyncBuilder {
141    fn as_ref(&self) -> &StatisticalGraphAsync {
142        &self.inner
143    }
144}
145
146/// A graph data
147#[derive(Debug, Clone, Default, Serialize, Deserialize)]
148pub struct StatisticalGraphData {
149    #[doc(hidden)]
150    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
151    extra: Option<String>,
152    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
153    client_id: Option<i32>,
154    /// Graph data in JSON format
155
156    #[serde(default)]
157    json_data: String,
158    /// If non-empty, a token which can be used to receive a zoomed in graph
159
160    #[serde(default)]
161    zoom_token: String,
162}
163
164impl RObject for StatisticalGraphData {
165    #[doc(hidden)]
166    fn extra(&self) -> Option<&str> {
167        self.extra.as_deref()
168    }
169    #[doc(hidden)]
170    fn client_id(&self) -> Option<i32> {
171        self.client_id
172    }
173}
174
175impl TDStatisticalGraph for StatisticalGraphData {}
176
177impl StatisticalGraphData {
178    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
179        Ok(serde_json::from_str(json.as_ref())?)
180    }
181    pub fn builder() -> StatisticalGraphDataBuilder {
182        let mut inner = StatisticalGraphData::default();
183        inner.extra = Some(Uuid::new_v4().to_string());
184
185        StatisticalGraphDataBuilder { inner }
186    }
187
188    pub fn json_data(&self) -> &String {
189        &self.json_data
190    }
191
192    pub fn zoom_token(&self) -> &String {
193        &self.zoom_token
194    }
195}
196
197#[doc(hidden)]
198pub struct StatisticalGraphDataBuilder {
199    inner: StatisticalGraphData,
200}
201
202#[deprecated]
203pub type RTDStatisticalGraphDataBuilder = StatisticalGraphDataBuilder;
204
205impl StatisticalGraphDataBuilder {
206    pub fn build(&self) -> StatisticalGraphData {
207        self.inner.clone()
208    }
209
210    pub fn json_data<T: AsRef<str>>(&mut self, json_data: T) -> &mut Self {
211        self.inner.json_data = json_data.as_ref().to_string();
212        self
213    }
214
215    pub fn zoom_token<T: AsRef<str>>(&mut self, zoom_token: T) -> &mut Self {
216        self.inner.zoom_token = zoom_token.as_ref().to_string();
217        self
218    }
219}
220
221impl AsRef<StatisticalGraphData> for StatisticalGraphData {
222    fn as_ref(&self) -> &StatisticalGraphData {
223        self
224    }
225}
226
227impl AsRef<StatisticalGraphData> for StatisticalGraphDataBuilder {
228    fn as_ref(&self) -> &StatisticalGraphData {
229        &self.inner
230    }
231}
232
233/// An error message to be shown to the user instead of the graph
234#[derive(Debug, Clone, Default, Serialize, Deserialize)]
235pub struct StatisticalGraphError {
236    #[doc(hidden)]
237    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
238    extra: Option<String>,
239    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
240    client_id: Option<i32>,
241    /// The error message
242
243    #[serde(default)]
244    error_message: String,
245}
246
247impl RObject for StatisticalGraphError {
248    #[doc(hidden)]
249    fn extra(&self) -> Option<&str> {
250        self.extra.as_deref()
251    }
252    #[doc(hidden)]
253    fn client_id(&self) -> Option<i32> {
254        self.client_id
255    }
256}
257
258impl TDStatisticalGraph for StatisticalGraphError {}
259
260impl StatisticalGraphError {
261    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
262        Ok(serde_json::from_str(json.as_ref())?)
263    }
264    pub fn builder() -> StatisticalGraphErrorBuilder {
265        let mut inner = StatisticalGraphError::default();
266        inner.extra = Some(Uuid::new_v4().to_string());
267
268        StatisticalGraphErrorBuilder { inner }
269    }
270
271    pub fn error_message(&self) -> &String {
272        &self.error_message
273    }
274}
275
276#[doc(hidden)]
277pub struct StatisticalGraphErrorBuilder {
278    inner: StatisticalGraphError,
279}
280
281#[deprecated]
282pub type RTDStatisticalGraphErrorBuilder = StatisticalGraphErrorBuilder;
283
284impl StatisticalGraphErrorBuilder {
285    pub fn build(&self) -> StatisticalGraphError {
286        self.inner.clone()
287    }
288
289    pub fn error_message<T: AsRef<str>>(&mut self, error_message: T) -> &mut Self {
290        self.inner.error_message = error_message.as_ref().to_string();
291        self
292    }
293}
294
295impl AsRef<StatisticalGraphError> for StatisticalGraphError {
296    fn as_ref(&self) -> &StatisticalGraphError {
297        self
298    }
299}
300
301impl AsRef<StatisticalGraphError> for StatisticalGraphErrorBuilder {
302    fn as_ref(&self) -> &StatisticalGraphError {
303        &self.inner
304    }
305}