rtdlib/types/
network_statistics_entry.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 TDNetworkStatisticsEntry: Debug + RObject {}
16
17#[derive(Debug, Clone, Serialize)]
19#[serde(untagged)]
20pub enum NetworkStatisticsEntry {
21 #[doc(hidden)] _Default(()),
22 Call(NetworkStatisticsEntryCall),
24 File(NetworkStatisticsEntryFile),
26
27}
28
29impl Default for NetworkStatisticsEntry {
30 fn default() -> Self { NetworkStatisticsEntry::_Default(()) }
31}
32
33impl<'de> Deserialize<'de> for NetworkStatisticsEntry {
34 fn deserialize<D>(deserializer: D) -> Result<NetworkStatisticsEntry, D::Error> where D: Deserializer<'de> {
35 use serde::de::Error;
36 rtd_enum_deserialize!(
37 NetworkStatisticsEntry,
38 (networkStatisticsEntryCall, Call);
39 (networkStatisticsEntryFile, File);
40
41 )(deserializer)
42 }
43}
44
45impl RObject for NetworkStatisticsEntry {
46 #[doc(hidden)] fn td_name(&self) -> &'static str {
47 match self {
48 NetworkStatisticsEntry::Call(t) => t.td_name(),
49 NetworkStatisticsEntry::File(t) => t.td_name(),
50
51 _ => "-1",
52 }
53 }
54 #[doc(hidden)] fn extra(&self) -> Option<String> {
55 match self {
56 NetworkStatisticsEntry::Call(t) => t.extra(),
57 NetworkStatisticsEntry::File(t) => t.extra(),
58
59 _ => None,
60 }
61 }
62 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
63}
64
65impl NetworkStatisticsEntry {
66 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
67 #[doc(hidden)] pub fn _is_default(&self) -> bool { if let NetworkStatisticsEntry::_Default(_) = self { true } else { false } }
68
69 pub fn is_call(&self) -> bool { if let NetworkStatisticsEntry::Call(_) = self { true } else { false } }
70 pub fn is_file(&self) -> bool { if let NetworkStatisticsEntry::File(_) = self { true } else { false } }
71
72 pub fn on_call<F: FnOnce(&NetworkStatisticsEntryCall)>(&self, fnc: F) -> &Self { if let NetworkStatisticsEntry::Call(t) = self { fnc(t) }; self }
73 pub fn on_file<F: FnOnce(&NetworkStatisticsEntryFile)>(&self, fnc: F) -> &Self { if let NetworkStatisticsEntry::File(t) = self { fnc(t) }; self }
74
75 pub fn as_call(&self) -> Option<&NetworkStatisticsEntryCall> { if let NetworkStatisticsEntry::Call(t) = self { return Some(t) } None }
76 pub fn as_file(&self) -> Option<&NetworkStatisticsEntryFile> { if let NetworkStatisticsEntry::File(t) = self { return Some(t) } None }
77
78
79
80 pub fn call<T: AsRef<NetworkStatisticsEntryCall>>(t: T) -> Self { NetworkStatisticsEntry::Call(t.as_ref().clone()) }
81
82 pub fn file<T: AsRef<NetworkStatisticsEntryFile>>(t: T) -> Self { NetworkStatisticsEntry::File(t.as_ref().clone()) }
83
84}
85
86impl AsRef<NetworkStatisticsEntry> for NetworkStatisticsEntry {
87 fn as_ref(&self) -> &NetworkStatisticsEntry { self }
88}
89
90
91
92
93
94
95
96#[derive(Debug, Clone, Default, Serialize, Deserialize)]
98pub struct NetworkStatisticsEntryCall {
99 #[doc(hidden)]
100 #[serde(rename(serialize = "@type", deserialize = "@type"))]
101 td_name: String,
102 #[doc(hidden)]
103 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
104 extra: Option<String>,
105 network_type: NetworkType,
107 sent_bytes: i64,
109 received_bytes: i64,
111 duration: f32,
113
114}
115
116impl RObject for NetworkStatisticsEntryCall {
117 #[doc(hidden)] fn td_name(&self) -> &'static str { "networkStatisticsEntryCall" }
118 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
119 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
120}
121
122
123impl TDNetworkStatisticsEntry for NetworkStatisticsEntryCall {}
124
125
126
127impl NetworkStatisticsEntryCall {
128 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
129 pub fn builder() -> RTDNetworkStatisticsEntryCallBuilder {
130 let mut inner = NetworkStatisticsEntryCall::default();
131 inner.td_name = "networkStatisticsEntryCall".to_string();
132 inner.extra = Some(Uuid::new_v4().to_string());
133 RTDNetworkStatisticsEntryCallBuilder { inner }
134 }
135
136 pub fn network_type(&self) -> &NetworkType { &self.network_type }
137
138 pub fn sent_bytes(&self) -> i64 { self.sent_bytes }
139
140 pub fn received_bytes(&self) -> i64 { self.received_bytes }
141
142 pub fn duration(&self) -> f32 { self.duration }
143
144}
145
146#[doc(hidden)]
147pub struct RTDNetworkStatisticsEntryCallBuilder {
148 inner: NetworkStatisticsEntryCall
149}
150
151impl RTDNetworkStatisticsEntryCallBuilder {
152 pub fn build(&self) -> NetworkStatisticsEntryCall { self.inner.clone() }
153
154
155 pub fn network_type<T: AsRef<NetworkType>>(&mut self, network_type: T) -> &mut Self {
156 self.inner.network_type = network_type.as_ref().clone();
157 self
158 }
159
160
161 pub fn sent_bytes(&mut self, sent_bytes: i64) -> &mut Self {
162 self.inner.sent_bytes = sent_bytes;
163 self
164 }
165
166
167 pub fn received_bytes(&mut self, received_bytes: i64) -> &mut Self {
168 self.inner.received_bytes = received_bytes;
169 self
170 }
171
172
173 pub fn duration(&mut self, duration: f32) -> &mut Self {
174 self.inner.duration = duration;
175 self
176 }
177
178}
179
180impl AsRef<NetworkStatisticsEntryCall> for NetworkStatisticsEntryCall {
181 fn as_ref(&self) -> &NetworkStatisticsEntryCall { self }
182}
183
184impl AsRef<NetworkStatisticsEntryCall> for RTDNetworkStatisticsEntryCallBuilder {
185 fn as_ref(&self) -> &NetworkStatisticsEntryCall { &self.inner }
186}
187
188
189
190
191
192
193
194#[derive(Debug, Clone, Default, Serialize, Deserialize)]
196pub struct NetworkStatisticsEntryFile {
197 #[doc(hidden)]
198 #[serde(rename(serialize = "@type", deserialize = "@type"))]
199 td_name: String,
200 #[doc(hidden)]
201 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
202 extra: Option<String>,
203 file_type: FileType,
205 network_type: NetworkType,
207 sent_bytes: i64,
209 received_bytes: i64,
211
212}
213
214impl RObject for NetworkStatisticsEntryFile {
215 #[doc(hidden)] fn td_name(&self) -> &'static str { "networkStatisticsEntryFile" }
216 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
217 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
218}
219
220
221impl TDNetworkStatisticsEntry for NetworkStatisticsEntryFile {}
222
223
224
225impl NetworkStatisticsEntryFile {
226 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
227 pub fn builder() -> RTDNetworkStatisticsEntryFileBuilder {
228 let mut inner = NetworkStatisticsEntryFile::default();
229 inner.td_name = "networkStatisticsEntryFile".to_string();
230 inner.extra = Some(Uuid::new_v4().to_string());
231 RTDNetworkStatisticsEntryFileBuilder { inner }
232 }
233
234 pub fn file_type(&self) -> &FileType { &self.file_type }
235
236 pub fn network_type(&self) -> &NetworkType { &self.network_type }
237
238 pub fn sent_bytes(&self) -> i64 { self.sent_bytes }
239
240 pub fn received_bytes(&self) -> i64 { self.received_bytes }
241
242}
243
244#[doc(hidden)]
245pub struct RTDNetworkStatisticsEntryFileBuilder {
246 inner: NetworkStatisticsEntryFile
247}
248
249impl RTDNetworkStatisticsEntryFileBuilder {
250 pub fn build(&self) -> NetworkStatisticsEntryFile { self.inner.clone() }
251
252
253 pub fn file_type<T: AsRef<FileType>>(&mut self, file_type: T) -> &mut Self {
254 self.inner.file_type = file_type.as_ref().clone();
255 self
256 }
257
258
259 pub fn network_type<T: AsRef<NetworkType>>(&mut self, network_type: T) -> &mut Self {
260 self.inner.network_type = network_type.as_ref().clone();
261 self
262 }
263
264
265 pub fn sent_bytes(&mut self, sent_bytes: i64) -> &mut Self {
266 self.inner.sent_bytes = sent_bytes;
267 self
268 }
269
270
271 pub fn received_bytes(&mut self, received_bytes: i64) -> &mut Self {
272 self.inner.received_bytes = received_bytes;
273 self
274 }
275
276}
277
278impl AsRef<NetworkStatisticsEntryFile> for NetworkStatisticsEntryFile {
279 fn as_ref(&self) -> &NetworkStatisticsEntryFile { self }
280}
281
282impl AsRef<NetworkStatisticsEntryFile> for RTDNetworkStatisticsEntryFileBuilder {
283 fn as_ref(&self) -> &NetworkStatisticsEntryFile { &self.inner }
284}
285
286
287