rtdlib/types/
input_file.rs

1
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
14/// TRAIT | Points to a file
15pub trait TDInputFile: Debug + RObject {}
16
17/// Points to a file
18#[derive(Debug, Clone, Serialize)]
19#[serde(untagged)]
20pub enum InputFile {
21  #[doc(hidden)] _Default(()),
22  /// A file generated by the application
23  Generated(InputFileGenerated),
24  /// A file defined by its unique ID
25  Id(InputFileId),
26  /// A file defined by a local path
27  Local(InputFileLocal),
28  /// A file defined by its remote ID. The remote ID is guaranteed to be usable only if the corresponding file is still accessible to the user and known to TDLib. For example, if the file is from a message, then the message must be not deleted and accessible to the user. If the file database is disabled, then the corresponding object with the file must be preloaded by the application
29  Remote(InputFileRemote),
30
31}
32
33impl Default for InputFile {
34  fn default() -> Self { InputFile::_Default(()) }
35}
36
37impl<'de> Deserialize<'de> for InputFile {
38  fn deserialize<D>(deserializer: D) -> Result<InputFile, D::Error> where D: Deserializer<'de> {
39    use serde::de::Error;
40    rtd_enum_deserialize!(
41      InputFile,
42      (inputFileGenerated, Generated);
43      (inputFileId, Id);
44      (inputFileLocal, Local);
45      (inputFileRemote, Remote);
46
47    )(deserializer)
48  }
49}
50
51impl RObject for InputFile {
52  #[doc(hidden)] fn td_name(&self) -> &'static str {
53    match self {
54      InputFile::Generated(t) => t.td_name(),
55      InputFile::Id(t) => t.td_name(),
56      InputFile::Local(t) => t.td_name(),
57      InputFile::Remote(t) => t.td_name(),
58
59      _ => "-1",
60    }
61  }
62  #[doc(hidden)] fn extra(&self) -> Option<String> {
63    match self {
64      InputFile::Generated(t) => t.extra(),
65      InputFile::Id(t) => t.extra(),
66      InputFile::Local(t) => t.extra(),
67      InputFile::Remote(t) => t.extra(),
68
69      _ => None,
70    }
71  }
72  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
73}
74
75impl InputFile {
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 InputFile::_Default(_) = self { true } else { false } }
78
79  pub fn is_generated(&self) -> bool { if let InputFile::Generated(_) = self { true } else { false } }
80  pub fn is_id(&self) -> bool { if let InputFile::Id(_) = self { true } else { false } }
81  pub fn is_local(&self) -> bool { if let InputFile::Local(_) = self { true } else { false } }
82  pub fn is_remote(&self) -> bool { if let InputFile::Remote(_) = self { true } else { false } }
83
84  pub fn on_generated<F: FnOnce(&InputFileGenerated)>(&self, fnc: F) -> &Self { if let InputFile::Generated(t) = self { fnc(t) }; self }
85  pub fn on_id<F: FnOnce(&InputFileId)>(&self, fnc: F) -> &Self { if let InputFile::Id(t) = self { fnc(t) }; self }
86  pub fn on_local<F: FnOnce(&InputFileLocal)>(&self, fnc: F) -> &Self { if let InputFile::Local(t) = self { fnc(t) }; self }
87  pub fn on_remote<F: FnOnce(&InputFileRemote)>(&self, fnc: F) -> &Self { if let InputFile::Remote(t) = self { fnc(t) }; self }
88
89  pub fn as_generated(&self) -> Option<&InputFileGenerated> { if let InputFile::Generated(t) = self { return Some(t) } None }
90  pub fn as_id(&self) -> Option<&InputFileId> { if let InputFile::Id(t) = self { return Some(t) } None }
91  pub fn as_local(&self) -> Option<&InputFileLocal> { if let InputFile::Local(t) = self { return Some(t) } None }
92  pub fn as_remote(&self) -> Option<&InputFileRemote> { if let InputFile::Remote(t) = self { return Some(t) } None }
93
94
95
96  pub fn generated<T: AsRef<InputFileGenerated>>(t: T) -> Self { InputFile::Generated(t.as_ref().clone()) }
97
98  pub fn id<T: AsRef<InputFileId>>(t: T) -> Self { InputFile::Id(t.as_ref().clone()) }
99
100  pub fn local<T: AsRef<InputFileLocal>>(t: T) -> Self { InputFile::Local(t.as_ref().clone()) }
101
102  pub fn remote<T: AsRef<InputFileRemote>>(t: T) -> Self { InputFile::Remote(t.as_ref().clone()) }
103
104}
105
106impl AsRef<InputFile> for InputFile {
107  fn as_ref(&self) -> &InputFile { self }
108}
109
110
111
112
113
114
115
116/// A file generated by the application
117#[derive(Debug, Clone, Default, Serialize, Deserialize)]
118pub struct InputFileGenerated {
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  /// Local path to a file from which the file is generated; may be empty if there is no such file
126  original_path: String,
127  /// String specifying the conversion applied to the original file; must be persistent across application restarts. Conversions beginning with '#' are reserved for internal TDLib usage
128  conversion: String,
129  /// Expected size of the generated file, in bytes; 0 if unknown
130  expected_size: i64,
131  
132}
133
134impl RObject for InputFileGenerated {
135  #[doc(hidden)] fn td_name(&self) -> &'static str { "inputFileGenerated" }
136  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
137  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
138}
139
140
141impl TDInputFile for InputFileGenerated {}
142
143
144
145impl InputFileGenerated {
146  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
147  pub fn builder() -> RTDInputFileGeneratedBuilder {
148    let mut inner = InputFileGenerated::default();
149    inner.td_name = "inputFileGenerated".to_string();
150    inner.extra = Some(Uuid::new_v4().to_string());
151    RTDInputFileGeneratedBuilder { inner }
152  }
153
154  pub fn original_path(&self) -> &String { &self.original_path }
155
156  pub fn conversion(&self) -> &String { &self.conversion }
157
158  pub fn expected_size(&self) -> i64 { self.expected_size }
159
160}
161
162#[doc(hidden)]
163pub struct RTDInputFileGeneratedBuilder {
164  inner: InputFileGenerated
165}
166
167impl RTDInputFileGeneratedBuilder {
168  pub fn build(&self) -> InputFileGenerated { self.inner.clone() }
169
170   
171  pub fn original_path<T: AsRef<str>>(&mut self, original_path: T) -> &mut Self {
172    self.inner.original_path = original_path.as_ref().to_string();
173    self
174  }
175
176   
177  pub fn conversion<T: AsRef<str>>(&mut self, conversion: T) -> &mut Self {
178    self.inner.conversion = conversion.as_ref().to_string();
179    self
180  }
181
182   
183  pub fn expected_size(&mut self, expected_size: i64) -> &mut Self {
184    self.inner.expected_size = expected_size;
185    self
186  }
187
188}
189
190impl AsRef<InputFileGenerated> for InputFileGenerated {
191  fn as_ref(&self) -> &InputFileGenerated { self }
192}
193
194impl AsRef<InputFileGenerated> for RTDInputFileGeneratedBuilder {
195  fn as_ref(&self) -> &InputFileGenerated { &self.inner }
196}
197
198
199
200
201
202
203
204/// A file defined by its unique ID
205#[derive(Debug, Clone, Default, Serialize, Deserialize)]
206pub struct InputFileId {
207  #[doc(hidden)]
208  #[serde(rename(serialize = "@type", deserialize = "@type"))]
209  td_name: String,
210  #[doc(hidden)]
211  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
212  extra: Option<String>,
213  /// Unique file identifier
214  id: i64,
215  
216}
217
218impl RObject for InputFileId {
219  #[doc(hidden)] fn td_name(&self) -> &'static str { "inputFileId" }
220  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
221  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
222}
223
224
225impl TDInputFile for InputFileId {}
226
227
228
229impl InputFileId {
230  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
231  pub fn builder() -> RTDInputFileIdBuilder {
232    let mut inner = InputFileId::default();
233    inner.td_name = "inputFileId".to_string();
234    inner.extra = Some(Uuid::new_v4().to_string());
235    RTDInputFileIdBuilder { inner }
236  }
237
238  pub fn id(&self) -> i64 { self.id }
239
240}
241
242#[doc(hidden)]
243pub struct RTDInputFileIdBuilder {
244  inner: InputFileId
245}
246
247impl RTDInputFileIdBuilder {
248  pub fn build(&self) -> InputFileId { self.inner.clone() }
249
250   
251  pub fn id(&mut self, id: i64) -> &mut Self {
252    self.inner.id = id;
253    self
254  }
255
256}
257
258impl AsRef<InputFileId> for InputFileId {
259  fn as_ref(&self) -> &InputFileId { self }
260}
261
262impl AsRef<InputFileId> for RTDInputFileIdBuilder {
263  fn as_ref(&self) -> &InputFileId { &self.inner }
264}
265
266
267
268
269
270
271
272/// A file defined by a local path
273#[derive(Debug, Clone, Default, Serialize, Deserialize)]
274pub struct InputFileLocal {
275  #[doc(hidden)]
276  #[serde(rename(serialize = "@type", deserialize = "@type"))]
277  td_name: String,
278  #[doc(hidden)]
279  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
280  extra: Option<String>,
281  /// Local path to the file
282  path: String,
283  
284}
285
286impl RObject for InputFileLocal {
287  #[doc(hidden)] fn td_name(&self) -> &'static str { "inputFileLocal" }
288  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
289  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
290}
291
292
293impl TDInputFile for InputFileLocal {}
294
295
296
297impl InputFileLocal {
298  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
299  pub fn builder() -> RTDInputFileLocalBuilder {
300    let mut inner = InputFileLocal::default();
301    inner.td_name = "inputFileLocal".to_string();
302    inner.extra = Some(Uuid::new_v4().to_string());
303    RTDInputFileLocalBuilder { inner }
304  }
305
306  pub fn path(&self) -> &String { &self.path }
307
308}
309
310#[doc(hidden)]
311pub struct RTDInputFileLocalBuilder {
312  inner: InputFileLocal
313}
314
315impl RTDInputFileLocalBuilder {
316  pub fn build(&self) -> InputFileLocal { self.inner.clone() }
317
318   
319  pub fn path<T: AsRef<str>>(&mut self, path: T) -> &mut Self {
320    self.inner.path = path.as_ref().to_string();
321    self
322  }
323
324}
325
326impl AsRef<InputFileLocal> for InputFileLocal {
327  fn as_ref(&self) -> &InputFileLocal { self }
328}
329
330impl AsRef<InputFileLocal> for RTDInputFileLocalBuilder {
331  fn as_ref(&self) -> &InputFileLocal { &self.inner }
332}
333
334
335
336
337
338
339
340/// A file defined by its remote ID. The remote ID is guaranteed to be usable only if the corresponding file is still accessible to the user and known to TDLib. For example, if the file is from a message, then the message must be not deleted and accessible to the user. If the file database is disabled, then the corresponding object with the file must be preloaded by the application
341#[derive(Debug, Clone, Default, Serialize, Deserialize)]
342pub struct InputFileRemote {
343  #[doc(hidden)]
344  #[serde(rename(serialize = "@type", deserialize = "@type"))]
345  td_name: String,
346  #[doc(hidden)]
347  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
348  extra: Option<String>,
349  /// Remote file identifier
350  id: String,
351  
352}
353
354impl RObject for InputFileRemote {
355  #[doc(hidden)] fn td_name(&self) -> &'static str { "inputFileRemote" }
356  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
357  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
358}
359
360
361impl TDInputFile for InputFileRemote {}
362
363
364
365impl InputFileRemote {
366  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
367  pub fn builder() -> RTDInputFileRemoteBuilder {
368    let mut inner = InputFileRemote::default();
369    inner.td_name = "inputFileRemote".to_string();
370    inner.extra = Some(Uuid::new_v4().to_string());
371    RTDInputFileRemoteBuilder { inner }
372  }
373
374  pub fn id(&self) -> &String { &self.id }
375
376}
377
378#[doc(hidden)]
379pub struct RTDInputFileRemoteBuilder {
380  inner: InputFileRemote
381}
382
383impl RTDInputFileRemoteBuilder {
384  pub fn build(&self) -> InputFileRemote { self.inner.clone() }
385
386   
387  pub fn id<T: AsRef<str>>(&mut self, id: T) -> &mut Self {
388    self.inner.id = id.as_ref().to_string();
389    self
390  }
391
392}
393
394impl AsRef<InputFileRemote> for InputFileRemote {
395  fn as_ref(&self) -> &InputFileRemote { self }
396}
397
398impl AsRef<InputFileRemote> for RTDInputFileRemoteBuilder {
399  fn as_ref(&self) -> &InputFileRemote { &self.inner }
400}
401
402
403