rust_tdlib/types/
network_statistics_entry.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7/// Contains statistics about network usage
8pub trait TDNetworkStatisticsEntry: Debug + RObject {}
9
10/// Contains statistics about network usage
11#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum NetworkStatisticsEntry {
14    #[doc(hidden)]
15    #[default]
16    _Default,
17    /// Contains information about the total amount of data that was used for calls
18    #[serde(rename = "networkStatisticsEntryCall")]
19    Call(NetworkStatisticsEntryCall),
20    /// Contains information about the total amount of data that was used to send and receive files
21    #[serde(rename = "networkStatisticsEntryFile")]
22    File(NetworkStatisticsEntryFile),
23}
24
25impl RObject for NetworkStatisticsEntry {
26    #[doc(hidden)]
27    fn extra(&self) -> Option<&str> {
28        match self {
29            NetworkStatisticsEntry::Call(t) => t.extra(),
30            NetworkStatisticsEntry::File(t) => t.extra(),
31
32            _ => None,
33        }
34    }
35    #[doc(hidden)]
36    fn client_id(&self) -> Option<i32> {
37        match self {
38            NetworkStatisticsEntry::Call(t) => t.client_id(),
39            NetworkStatisticsEntry::File(t) => t.client_id(),
40
41            _ => None,
42        }
43    }
44}
45
46impl NetworkStatisticsEntry {
47    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
48        Ok(serde_json::from_str(json.as_ref())?)
49    }
50    #[doc(hidden)]
51    pub fn _is_default(&self) -> bool {
52        matches!(self, NetworkStatisticsEntry::_Default)
53    }
54}
55
56impl AsRef<NetworkStatisticsEntry> for NetworkStatisticsEntry {
57    fn as_ref(&self) -> &NetworkStatisticsEntry {
58        self
59    }
60}
61
62/// Contains information about the total amount of data that was used for calls
63#[derive(Debug, Clone, Default, Serialize, Deserialize)]
64pub struct NetworkStatisticsEntryCall {
65    #[doc(hidden)]
66    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
67    extra: Option<String>,
68    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
69    client_id: Option<i32>,
70    /// Type of the network the data was sent through. Call setNetworkType to maintain the actual network type
71
72    #[serde(skip_serializing_if = "NetworkType::_is_default")]
73    network_type: NetworkType,
74    /// Total number of bytes sent
75
76    #[serde(default)]
77    sent_bytes: i64,
78    /// Total number of bytes received
79
80    #[serde(default)]
81    received_bytes: i64,
82    /// Total call duration, in seconds
83
84    #[serde(default)]
85    duration: f32,
86}
87
88impl RObject for NetworkStatisticsEntryCall {
89    #[doc(hidden)]
90    fn extra(&self) -> Option<&str> {
91        self.extra.as_deref()
92    }
93    #[doc(hidden)]
94    fn client_id(&self) -> Option<i32> {
95        self.client_id
96    }
97}
98
99impl TDNetworkStatisticsEntry for NetworkStatisticsEntryCall {}
100
101impl NetworkStatisticsEntryCall {
102    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
103        Ok(serde_json::from_str(json.as_ref())?)
104    }
105    pub fn builder() -> NetworkStatisticsEntryCallBuilder {
106        let mut inner = NetworkStatisticsEntryCall::default();
107        inner.extra = Some(Uuid::new_v4().to_string());
108
109        NetworkStatisticsEntryCallBuilder { inner }
110    }
111
112    pub fn network_type(&self) -> &NetworkType {
113        &self.network_type
114    }
115
116    pub fn sent_bytes(&self) -> i64 {
117        self.sent_bytes
118    }
119
120    pub fn received_bytes(&self) -> i64 {
121        self.received_bytes
122    }
123
124    pub fn duration(&self) -> f32 {
125        self.duration
126    }
127}
128
129#[doc(hidden)]
130pub struct NetworkStatisticsEntryCallBuilder {
131    inner: NetworkStatisticsEntryCall,
132}
133
134#[deprecated]
135pub type RTDNetworkStatisticsEntryCallBuilder = NetworkStatisticsEntryCallBuilder;
136
137impl NetworkStatisticsEntryCallBuilder {
138    pub fn build(&self) -> NetworkStatisticsEntryCall {
139        self.inner.clone()
140    }
141
142    pub fn network_type<T: AsRef<NetworkType>>(&mut self, network_type: T) -> &mut Self {
143        self.inner.network_type = network_type.as_ref().clone();
144        self
145    }
146
147    pub fn sent_bytes(&mut self, sent_bytes: i64) -> &mut Self {
148        self.inner.sent_bytes = sent_bytes;
149        self
150    }
151
152    pub fn received_bytes(&mut self, received_bytes: i64) -> &mut Self {
153        self.inner.received_bytes = received_bytes;
154        self
155    }
156
157    pub fn duration(&mut self, duration: f32) -> &mut Self {
158        self.inner.duration = duration;
159        self
160    }
161}
162
163impl AsRef<NetworkStatisticsEntryCall> for NetworkStatisticsEntryCall {
164    fn as_ref(&self) -> &NetworkStatisticsEntryCall {
165        self
166    }
167}
168
169impl AsRef<NetworkStatisticsEntryCall> for NetworkStatisticsEntryCallBuilder {
170    fn as_ref(&self) -> &NetworkStatisticsEntryCall {
171        &self.inner
172    }
173}
174
175/// Contains information about the total amount of data that was used to send and receive files
176#[derive(Debug, Clone, Default, Serialize, Deserialize)]
177pub struct NetworkStatisticsEntryFile {
178    #[doc(hidden)]
179    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
180    extra: Option<String>,
181    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
182    client_id: Option<i32>,
183    /// Type of the file the data is part of; pass null if the data isn't related to files
184
185    #[serde(skip_serializing_if = "FileType::_is_default")]
186    file_type: FileType,
187    /// Type of the network the data was sent through. Call setNetworkType to maintain the actual network type
188
189    #[serde(skip_serializing_if = "NetworkType::_is_default")]
190    network_type: NetworkType,
191    /// Total number of bytes sent
192
193    #[serde(default)]
194    sent_bytes: i64,
195    /// Total number of bytes received
196
197    #[serde(default)]
198    received_bytes: i64,
199}
200
201impl RObject for NetworkStatisticsEntryFile {
202    #[doc(hidden)]
203    fn extra(&self) -> Option<&str> {
204        self.extra.as_deref()
205    }
206    #[doc(hidden)]
207    fn client_id(&self) -> Option<i32> {
208        self.client_id
209    }
210}
211
212impl TDNetworkStatisticsEntry for NetworkStatisticsEntryFile {}
213
214impl NetworkStatisticsEntryFile {
215    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
216        Ok(serde_json::from_str(json.as_ref())?)
217    }
218    pub fn builder() -> NetworkStatisticsEntryFileBuilder {
219        let mut inner = NetworkStatisticsEntryFile::default();
220        inner.extra = Some(Uuid::new_v4().to_string());
221
222        NetworkStatisticsEntryFileBuilder { inner }
223    }
224
225    pub fn file_type(&self) -> &FileType {
226        &self.file_type
227    }
228
229    pub fn network_type(&self) -> &NetworkType {
230        &self.network_type
231    }
232
233    pub fn sent_bytes(&self) -> i64 {
234        self.sent_bytes
235    }
236
237    pub fn received_bytes(&self) -> i64 {
238        self.received_bytes
239    }
240}
241
242#[doc(hidden)]
243pub struct NetworkStatisticsEntryFileBuilder {
244    inner: NetworkStatisticsEntryFile,
245}
246
247#[deprecated]
248pub type RTDNetworkStatisticsEntryFileBuilder = NetworkStatisticsEntryFileBuilder;
249
250impl NetworkStatisticsEntryFileBuilder {
251    pub fn build(&self) -> NetworkStatisticsEntryFile {
252        self.inner.clone()
253    }
254
255    pub fn file_type<T: AsRef<FileType>>(&mut self, file_type: T) -> &mut Self {
256        self.inner.file_type = file_type.as_ref().clone();
257        self
258    }
259
260    pub fn network_type<T: AsRef<NetworkType>>(&mut self, network_type: T) -> &mut Self {
261        self.inner.network_type = network_type.as_ref().clone();
262        self
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    pub fn received_bytes(&mut self, received_bytes: i64) -> &mut Self {
271        self.inner.received_bytes = received_bytes;
272        self
273    }
274}
275
276impl AsRef<NetworkStatisticsEntryFile> for NetworkStatisticsEntryFile {
277    fn as_ref(&self) -> &NetworkStatisticsEntryFile {
278        self
279    }
280}
281
282impl AsRef<NetworkStatisticsEntryFile> for NetworkStatisticsEntryFileBuilder {
283    fn as_ref(&self) -> &NetworkStatisticsEntryFile {
284        &self.inner
285    }
286}