rust_tdlib/types/
input_file.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7pub trait TDInputFile: Debug + RObject {}
9
10#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum InputFile {
14 #[doc(hidden)]
15 #[default]
16 _Default,
17 #[serde(rename = "inputFileGenerated")]
19 Generated(InputFileGenerated),
20 #[serde(rename = "inputFileId")]
22 Id(InputFileId),
23 #[serde(rename = "inputFileLocal")]
25 Local(InputFileLocal),
26 #[serde(rename = "inputFileRemote")]
28 Remote(InputFileRemote),
29}
30
31impl RObject for InputFile {
32 #[doc(hidden)]
33 fn extra(&self) -> Option<&str> {
34 match self {
35 InputFile::Generated(t) => t.extra(),
36 InputFile::Id(t) => t.extra(),
37 InputFile::Local(t) => t.extra(),
38 InputFile::Remote(t) => t.extra(),
39
40 _ => None,
41 }
42 }
43 #[doc(hidden)]
44 fn client_id(&self) -> Option<i32> {
45 match self {
46 InputFile::Generated(t) => t.client_id(),
47 InputFile::Id(t) => t.client_id(),
48 InputFile::Local(t) => t.client_id(),
49 InputFile::Remote(t) => t.client_id(),
50
51 _ => None,
52 }
53 }
54}
55
56impl InputFile {
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, InputFile::_Default)
63 }
64}
65
66impl AsRef<InputFile> for InputFile {
67 fn as_ref(&self) -> &InputFile {
68 self
69 }
70}
71
72#[derive(Debug, Clone, Default, Serialize, Deserialize)]
74pub struct InputFileGenerated {
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 #[serde(default)]
83 original_path: String,
84 #[serde(default)]
87 conversion: String,
88 #[serde(default)]
91 expected_size: i32,
92}
93
94impl RObject for InputFileGenerated {
95 #[doc(hidden)]
96 fn extra(&self) -> Option<&str> {
97 self.extra.as_deref()
98 }
99 #[doc(hidden)]
100 fn client_id(&self) -> Option<i32> {
101 self.client_id
102 }
103}
104
105impl TDInputFile for InputFileGenerated {}
106
107impl InputFileGenerated {
108 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
109 Ok(serde_json::from_str(json.as_ref())?)
110 }
111 pub fn builder() -> InputFileGeneratedBuilder {
112 let mut inner = InputFileGenerated::default();
113 inner.extra = Some(Uuid::new_v4().to_string());
114
115 InputFileGeneratedBuilder { inner }
116 }
117
118 pub fn original_path(&self) -> &String {
119 &self.original_path
120 }
121
122 pub fn conversion(&self) -> &String {
123 &self.conversion
124 }
125
126 pub fn expected_size(&self) -> i32 {
127 self.expected_size
128 }
129}
130
131#[doc(hidden)]
132pub struct InputFileGeneratedBuilder {
133 inner: InputFileGenerated,
134}
135
136#[deprecated]
137pub type RTDInputFileGeneratedBuilder = InputFileGeneratedBuilder;
138
139impl InputFileGeneratedBuilder {
140 pub fn build(&self) -> InputFileGenerated {
141 self.inner.clone()
142 }
143
144 pub fn original_path<T: AsRef<str>>(&mut self, original_path: T) -> &mut Self {
145 self.inner.original_path = original_path.as_ref().to_string();
146 self
147 }
148
149 pub fn conversion<T: AsRef<str>>(&mut self, conversion: T) -> &mut Self {
150 self.inner.conversion = conversion.as_ref().to_string();
151 self
152 }
153
154 pub fn expected_size(&mut self, expected_size: i32) -> &mut Self {
155 self.inner.expected_size = expected_size;
156 self
157 }
158}
159
160impl AsRef<InputFileGenerated> for InputFileGenerated {
161 fn as_ref(&self) -> &InputFileGenerated {
162 self
163 }
164}
165
166impl AsRef<InputFileGenerated> for InputFileGeneratedBuilder {
167 fn as_ref(&self) -> &InputFileGenerated {
168 &self.inner
169 }
170}
171
172#[derive(Debug, Clone, Default, Serialize, Deserialize)]
174pub struct InputFileId {
175 #[doc(hidden)]
176 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
177 extra: Option<String>,
178 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
179 client_id: Option<i32>,
180 #[serde(default)]
183 id: i32,
184}
185
186impl RObject for InputFileId {
187 #[doc(hidden)]
188 fn extra(&self) -> Option<&str> {
189 self.extra.as_deref()
190 }
191 #[doc(hidden)]
192 fn client_id(&self) -> Option<i32> {
193 self.client_id
194 }
195}
196
197impl TDInputFile for InputFileId {}
198
199impl InputFileId {
200 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
201 Ok(serde_json::from_str(json.as_ref())?)
202 }
203 pub fn builder() -> InputFileIdBuilder {
204 let mut inner = InputFileId::default();
205 inner.extra = Some(Uuid::new_v4().to_string());
206
207 InputFileIdBuilder { inner }
208 }
209
210 pub fn id(&self) -> i32 {
211 self.id
212 }
213}
214
215#[doc(hidden)]
216pub struct InputFileIdBuilder {
217 inner: InputFileId,
218}
219
220#[deprecated]
221pub type RTDInputFileIdBuilder = InputFileIdBuilder;
222
223impl InputFileIdBuilder {
224 pub fn build(&self) -> InputFileId {
225 self.inner.clone()
226 }
227
228 pub fn id(&mut self, id: i32) -> &mut Self {
229 self.inner.id = id;
230 self
231 }
232}
233
234impl AsRef<InputFileId> for InputFileId {
235 fn as_ref(&self) -> &InputFileId {
236 self
237 }
238}
239
240impl AsRef<InputFileId> for InputFileIdBuilder {
241 fn as_ref(&self) -> &InputFileId {
242 &self.inner
243 }
244}
245
246#[derive(Debug, Clone, Default, Serialize, Deserialize)]
248pub struct InputFileLocal {
249 #[doc(hidden)]
250 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
251 extra: Option<String>,
252 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
253 client_id: Option<i32>,
254 #[serde(default)]
257 path: String,
258}
259
260impl RObject for InputFileLocal {
261 #[doc(hidden)]
262 fn extra(&self) -> Option<&str> {
263 self.extra.as_deref()
264 }
265 #[doc(hidden)]
266 fn client_id(&self) -> Option<i32> {
267 self.client_id
268 }
269}
270
271impl TDInputFile for InputFileLocal {}
272
273impl InputFileLocal {
274 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
275 Ok(serde_json::from_str(json.as_ref())?)
276 }
277 pub fn builder() -> InputFileLocalBuilder {
278 let mut inner = InputFileLocal::default();
279 inner.extra = Some(Uuid::new_v4().to_string());
280
281 InputFileLocalBuilder { inner }
282 }
283
284 pub fn path(&self) -> &String {
285 &self.path
286 }
287}
288
289#[doc(hidden)]
290pub struct InputFileLocalBuilder {
291 inner: InputFileLocal,
292}
293
294#[deprecated]
295pub type RTDInputFileLocalBuilder = InputFileLocalBuilder;
296
297impl InputFileLocalBuilder {
298 pub fn build(&self) -> InputFileLocal {
299 self.inner.clone()
300 }
301
302 pub fn path<T: AsRef<str>>(&mut self, path: T) -> &mut Self {
303 self.inner.path = path.as_ref().to_string();
304 self
305 }
306}
307
308impl AsRef<InputFileLocal> for InputFileLocal {
309 fn as_ref(&self) -> &InputFileLocal {
310 self
311 }
312}
313
314impl AsRef<InputFileLocal> for InputFileLocalBuilder {
315 fn as_ref(&self) -> &InputFileLocal {
316 &self.inner
317 }
318}
319
320#[derive(Debug, Clone, Default, Serialize, Deserialize)]
322pub struct InputFileRemote {
323 #[doc(hidden)]
324 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
325 extra: Option<String>,
326 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
327 client_id: Option<i32>,
328 #[serde(default)]
331 id: String,
332}
333
334impl RObject for InputFileRemote {
335 #[doc(hidden)]
336 fn extra(&self) -> Option<&str> {
337 self.extra.as_deref()
338 }
339 #[doc(hidden)]
340 fn client_id(&self) -> Option<i32> {
341 self.client_id
342 }
343}
344
345impl TDInputFile for InputFileRemote {}
346
347impl InputFileRemote {
348 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
349 Ok(serde_json::from_str(json.as_ref())?)
350 }
351 pub fn builder() -> InputFileRemoteBuilder {
352 let mut inner = InputFileRemote::default();
353 inner.extra = Some(Uuid::new_v4().to_string());
354
355 InputFileRemoteBuilder { inner }
356 }
357
358 pub fn id(&self) -> &String {
359 &self.id
360 }
361}
362
363#[doc(hidden)]
364pub struct InputFileRemoteBuilder {
365 inner: InputFileRemote,
366}
367
368#[deprecated]
369pub type RTDInputFileRemoteBuilder = InputFileRemoteBuilder;
370
371impl InputFileRemoteBuilder {
372 pub fn build(&self) -> InputFileRemote {
373 self.inner.clone()
374 }
375
376 pub fn id<T: AsRef<str>>(&mut self, id: T) -> &mut Self {
377 self.inner.id = id.as_ref().to_string();
378 self
379 }
380}
381
382impl AsRef<InputFileRemote> for InputFileRemote {
383 fn as_ref(&self) -> &InputFileRemote {
384 self
385 }
386}
387
388impl AsRef<InputFileRemote> for InputFileRemoteBuilder {
389 fn as_ref(&self) -> &InputFileRemote {
390 &self.inner
391 }
392}