rtdlib/types/
statistical_graph.rs1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9use std::fmt::Debug;
10use serde::de::{Deserialize, Deserializer};
11
12
13
14pub trait TDStatisticalGraph: Debug + RObject {}
16
17#[derive(Debug, Clone, Serialize)]
19#[serde(untagged)]
20pub enum StatisticalGraph {
21 #[doc(hidden)] _Default(()),
22 GetStatisticalGraph(GetStatisticalGraph),
24 Async(StatisticalGraphAsync),
26 Data(StatisticalGraphData),
28 Error(StatisticalGraphError),
30
31}
32
33impl Default for StatisticalGraph {
34 fn default() -> Self { StatisticalGraph::_Default(()) }
35}
36
37impl<'de> Deserialize<'de> for StatisticalGraph {
38 fn deserialize<D>(deserializer: D) -> Result<StatisticalGraph, D::Error> where D: Deserializer<'de> {
39 use serde::de::Error;
40 rtd_enum_deserialize!(
41 StatisticalGraph,
42 (getStatisticalGraph, GetStatisticalGraph);
43 (statisticalGraphAsync, Async);
44 (statisticalGraphData, Data);
45 (statisticalGraphError, Error);
46
47 )(deserializer)
48 }
49}
50
51impl RObject for StatisticalGraph {
52 #[doc(hidden)] fn td_name(&self) -> &'static str {
53 match self {
54 StatisticalGraph::GetStatisticalGraph(t) => t.td_name(),
55 StatisticalGraph::Async(t) => t.td_name(),
56 StatisticalGraph::Data(t) => t.td_name(),
57 StatisticalGraph::Error(t) => t.td_name(),
58
59 _ => "-1",
60 }
61 }
62 #[doc(hidden)] fn extra(&self) -> Option<String> {
63 match self {
64 StatisticalGraph::GetStatisticalGraph(t) => t.extra(),
65 StatisticalGraph::Async(t) => t.extra(),
66 StatisticalGraph::Data(t) => t.extra(),
67 StatisticalGraph::Error(t) => t.extra(),
68
69 _ => None,
70 }
71 }
72 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
73}
74
75impl StatisticalGraph {
76 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
77 #[doc(hidden)] pub fn _is_default(&self) -> bool { if let StatisticalGraph::_Default(_) = self { true } else { false } }
78
79 pub fn is_get_statistical_graph(&self) -> bool { if let StatisticalGraph::GetStatisticalGraph(_) = self { true } else { false } }
80 pub fn is_async(&self) -> bool { if let StatisticalGraph::Async(_) = self { true } else { false } }
81 pub fn is_data(&self) -> bool { if let StatisticalGraph::Data(_) = self { true } else { false } }
82 pub fn is_error(&self) -> bool { if let StatisticalGraph::Error(_) = self { true } else { false } }
83
84 pub fn on_get_statistical_graph<F: FnOnce(&GetStatisticalGraph)>(&self, fnc: F) -> &Self { if let StatisticalGraph::GetStatisticalGraph(t) = self { fnc(t) }; self }
85 pub fn on_async<F: FnOnce(&StatisticalGraphAsync)>(&self, fnc: F) -> &Self { if let StatisticalGraph::Async(t) = self { fnc(t) }; self }
86 pub fn on_data<F: FnOnce(&StatisticalGraphData)>(&self, fnc: F) -> &Self { if let StatisticalGraph::Data(t) = self { fnc(t) }; self }
87 pub fn on_error<F: FnOnce(&StatisticalGraphError)>(&self, fnc: F) -> &Self { if let StatisticalGraph::Error(t) = self { fnc(t) }; self }
88
89 pub fn as_get_statistical_graph(&self) -> Option<&GetStatisticalGraph> { if let StatisticalGraph::GetStatisticalGraph(t) = self { return Some(t) } None }
90 pub fn as_async(&self) -> Option<&StatisticalGraphAsync> { if let StatisticalGraph::Async(t) = self { return Some(t) } None }
91 pub fn as_data(&self) -> Option<&StatisticalGraphData> { if let StatisticalGraph::Data(t) = self { return Some(t) } None }
92 pub fn as_error(&self) -> Option<&StatisticalGraphError> { if let StatisticalGraph::Error(t) = self { return Some(t) } None }
93
94
95
96 pub fn get_statistical_graph<T: AsRef<GetStatisticalGraph>>(t: T) -> Self { StatisticalGraph::GetStatisticalGraph(t.as_ref().clone()) }
97
98 pub fn async_<T: AsRef<StatisticalGraphAsync>>(t: T) -> Self { StatisticalGraph::Async(t.as_ref().clone()) }
99
100 pub fn data<T: AsRef<StatisticalGraphData>>(t: T) -> Self { StatisticalGraph::Data(t.as_ref().clone()) }
101
102 pub fn error<T: AsRef<StatisticalGraphError>>(t: T) -> Self { StatisticalGraph::Error(t.as_ref().clone()) }
103
104}
105
106impl AsRef<StatisticalGraph> for StatisticalGraph {
107 fn as_ref(&self) -> &StatisticalGraph { self }
108}
109
110
111
112
113
114
115
116#[derive(Debug, Clone, Default, Serialize, Deserialize)]
118pub struct StatisticalGraphAsync {
119 #[doc(hidden)]
120 #[serde(rename(serialize = "@type", deserialize = "@type"))]
121 td_name: String,
122 #[doc(hidden)]
123 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
124 extra: Option<String>,
125 token: String,
127
128}
129
130impl RObject for StatisticalGraphAsync {
131 #[doc(hidden)] fn td_name(&self) -> &'static str { "statisticalGraphAsync" }
132 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
133 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
134}
135
136
137impl TDStatisticalGraph for StatisticalGraphAsync {}
138
139
140
141impl StatisticalGraphAsync {
142 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
143 pub fn builder() -> RTDStatisticalGraphAsyncBuilder {
144 let mut inner = StatisticalGraphAsync::default();
145 inner.td_name = "statisticalGraphAsync".to_string();
146 inner.extra = Some(Uuid::new_v4().to_string());
147 RTDStatisticalGraphAsyncBuilder { inner }
148 }
149
150 pub fn token(&self) -> &String { &self.token }
151
152}
153
154#[doc(hidden)]
155pub struct RTDStatisticalGraphAsyncBuilder {
156 inner: StatisticalGraphAsync
157}
158
159impl RTDStatisticalGraphAsyncBuilder {
160 pub fn build(&self) -> StatisticalGraphAsync { self.inner.clone() }
161
162
163 pub fn token<T: AsRef<str>>(&mut self, token: T) -> &mut Self {
164 self.inner.token = token.as_ref().to_string();
165 self
166 }
167
168}
169
170impl AsRef<StatisticalGraphAsync> for StatisticalGraphAsync {
171 fn as_ref(&self) -> &StatisticalGraphAsync { self }
172}
173
174impl AsRef<StatisticalGraphAsync> for RTDStatisticalGraphAsyncBuilder {
175 fn as_ref(&self) -> &StatisticalGraphAsync { &self.inner }
176}
177
178
179
180
181
182
183
184#[derive(Debug, Clone, Default, Serialize, Deserialize)]
186pub struct StatisticalGraphData {
187 #[doc(hidden)]
188 #[serde(rename(serialize = "@type", deserialize = "@type"))]
189 td_name: String,
190 #[doc(hidden)]
191 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
192 extra: Option<String>,
193 json_data: String,
195 zoom_token: String,
197
198}
199
200impl RObject for StatisticalGraphData {
201 #[doc(hidden)] fn td_name(&self) -> &'static str { "statisticalGraphData" }
202 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
203 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
204}
205
206
207impl TDStatisticalGraph for StatisticalGraphData {}
208
209
210
211impl StatisticalGraphData {
212 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
213 pub fn builder() -> RTDStatisticalGraphDataBuilder {
214 let mut inner = StatisticalGraphData::default();
215 inner.td_name = "statisticalGraphData".to_string();
216 inner.extra = Some(Uuid::new_v4().to_string());
217 RTDStatisticalGraphDataBuilder { inner }
218 }
219
220 pub fn json_data(&self) -> &String { &self.json_data }
221
222 pub fn zoom_token(&self) -> &String { &self.zoom_token }
223
224}
225
226#[doc(hidden)]
227pub struct RTDStatisticalGraphDataBuilder {
228 inner: StatisticalGraphData
229}
230
231impl RTDStatisticalGraphDataBuilder {
232 pub fn build(&self) -> StatisticalGraphData { self.inner.clone() }
233
234
235 pub fn json_data<T: AsRef<str>>(&mut self, json_data: T) -> &mut Self {
236 self.inner.json_data = json_data.as_ref().to_string();
237 self
238 }
239
240
241 pub fn zoom_token<T: AsRef<str>>(&mut self, zoom_token: T) -> &mut Self {
242 self.inner.zoom_token = zoom_token.as_ref().to_string();
243 self
244 }
245
246}
247
248impl AsRef<StatisticalGraphData> for StatisticalGraphData {
249 fn as_ref(&self) -> &StatisticalGraphData { self }
250}
251
252impl AsRef<StatisticalGraphData> for RTDStatisticalGraphDataBuilder {
253 fn as_ref(&self) -> &StatisticalGraphData { &self.inner }
254}
255
256
257
258
259
260
261
262#[derive(Debug, Clone, Default, Serialize, Deserialize)]
264pub struct StatisticalGraphError {
265 #[doc(hidden)]
266 #[serde(rename(serialize = "@type", deserialize = "@type"))]
267 td_name: String,
268 #[doc(hidden)]
269 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
270 extra: Option<String>,
271 error_message: String,
273
274}
275
276impl RObject for StatisticalGraphError {
277 #[doc(hidden)] fn td_name(&self) -> &'static str { "statisticalGraphError" }
278 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
279 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
280}
281
282
283impl TDStatisticalGraph for StatisticalGraphError {}
284
285
286
287impl StatisticalGraphError {
288 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
289 pub fn builder() -> RTDStatisticalGraphErrorBuilder {
290 let mut inner = StatisticalGraphError::default();
291 inner.td_name = "statisticalGraphError".to_string();
292 inner.extra = Some(Uuid::new_v4().to_string());
293 RTDStatisticalGraphErrorBuilder { inner }
294 }
295
296 pub fn error_message(&self) -> &String { &self.error_message }
297
298}
299
300#[doc(hidden)]
301pub struct RTDStatisticalGraphErrorBuilder {
302 inner: StatisticalGraphError
303}
304
305impl RTDStatisticalGraphErrorBuilder {
306 pub fn build(&self) -> StatisticalGraphError { self.inner.clone() }
307
308
309 pub fn error_message<T: AsRef<str>>(&mut self, error_message: T) -> &mut Self {
310 self.inner.error_message = error_message.as_ref().to_string();
311 self
312 }
313
314}
315
316impl AsRef<StatisticalGraphError> for StatisticalGraphError {
317 fn as_ref(&self) -> &StatisticalGraphError { self }
318}
319
320impl AsRef<StatisticalGraphError> for RTDStatisticalGraphErrorBuilder {
321 fn as_ref(&self) -> &StatisticalGraphError { &self.inner }
322}
323
324
325