rtdlib/types/
thumbnail_format.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 | Describes format of the thumbnail
15pub trait TDThumbnailFormat: Debug + RObject {}
16
17/// Describes format of the thumbnail
18#[derive(Debug, Clone, Serialize)]
19#[serde(untagged)]
20pub enum ThumbnailFormat {
21  #[doc(hidden)] _Default(()),
22  /// The thumbnail is in static GIF format. It will be used only for some bot inline results
23  Gif(ThumbnailFormatGif),
24  /// The thumbnail is in JPEG format
25  Jpeg(ThumbnailFormatJpeg),
26  /// The thumbnail is in MPEG4 format. It will be used only for some animations and videos
27  Mpeg4(ThumbnailFormatMpeg4),
28  /// The thumbnail is in PNG format. It will be used only for background patterns
29  Png(ThumbnailFormatPng),
30  /// The thumbnail is in TGS format. It will be used only for animated sticker sets
31  Tgs(ThumbnailFormatTgs),
32  /// The thumbnail is in WEBP format. It will be used only for some stickers
33  Webp(ThumbnailFormatWebp),
34
35}
36
37impl Default for ThumbnailFormat {
38  fn default() -> Self { ThumbnailFormat::_Default(()) }
39}
40
41impl<'de> Deserialize<'de> for ThumbnailFormat {
42  fn deserialize<D>(deserializer: D) -> Result<ThumbnailFormat, D::Error> where D: Deserializer<'de> {
43    use serde::de::Error;
44    rtd_enum_deserialize!(
45      ThumbnailFormat,
46      (thumbnailFormatGif, Gif);
47      (thumbnailFormatJpeg, Jpeg);
48      (thumbnailFormatMpeg4, Mpeg4);
49      (thumbnailFormatPng, Png);
50      (thumbnailFormatTgs, Tgs);
51      (thumbnailFormatWebp, Webp);
52
53    )(deserializer)
54  }
55}
56
57impl RObject for ThumbnailFormat {
58  #[doc(hidden)] fn td_name(&self) -> &'static str {
59    match self {
60      ThumbnailFormat::Gif(t) => t.td_name(),
61      ThumbnailFormat::Jpeg(t) => t.td_name(),
62      ThumbnailFormat::Mpeg4(t) => t.td_name(),
63      ThumbnailFormat::Png(t) => t.td_name(),
64      ThumbnailFormat::Tgs(t) => t.td_name(),
65      ThumbnailFormat::Webp(t) => t.td_name(),
66
67      _ => "-1",
68    }
69  }
70  #[doc(hidden)] fn extra(&self) -> Option<String> {
71    match self {
72      ThumbnailFormat::Gif(t) => t.extra(),
73      ThumbnailFormat::Jpeg(t) => t.extra(),
74      ThumbnailFormat::Mpeg4(t) => t.extra(),
75      ThumbnailFormat::Png(t) => t.extra(),
76      ThumbnailFormat::Tgs(t) => t.extra(),
77      ThumbnailFormat::Webp(t) => t.extra(),
78
79      _ => None,
80    }
81  }
82  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
83}
84
85impl ThumbnailFormat {
86  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
87  #[doc(hidden)] pub fn _is_default(&self) -> bool { if let ThumbnailFormat::_Default(_) = self { true } else { false } }
88
89  pub fn is_gif(&self) -> bool { if let ThumbnailFormat::Gif(_) = self { true } else { false } }
90  pub fn is_jpeg(&self) -> bool { if let ThumbnailFormat::Jpeg(_) = self { true } else { false } }
91  pub fn is_mpeg4(&self) -> bool { if let ThumbnailFormat::Mpeg4(_) = self { true } else { false } }
92  pub fn is_png(&self) -> bool { if let ThumbnailFormat::Png(_) = self { true } else { false } }
93  pub fn is_tgs(&self) -> bool { if let ThumbnailFormat::Tgs(_) = self { true } else { false } }
94  pub fn is_webp(&self) -> bool { if let ThumbnailFormat::Webp(_) = self { true } else { false } }
95
96  pub fn on_gif<F: FnOnce(&ThumbnailFormatGif)>(&self, fnc: F) -> &Self { if let ThumbnailFormat::Gif(t) = self { fnc(t) }; self }
97  pub fn on_jpeg<F: FnOnce(&ThumbnailFormatJpeg)>(&self, fnc: F) -> &Self { if let ThumbnailFormat::Jpeg(t) = self { fnc(t) }; self }
98  pub fn on_mpeg4<F: FnOnce(&ThumbnailFormatMpeg4)>(&self, fnc: F) -> &Self { if let ThumbnailFormat::Mpeg4(t) = self { fnc(t) }; self }
99  pub fn on_png<F: FnOnce(&ThumbnailFormatPng)>(&self, fnc: F) -> &Self { if let ThumbnailFormat::Png(t) = self { fnc(t) }; self }
100  pub fn on_tgs<F: FnOnce(&ThumbnailFormatTgs)>(&self, fnc: F) -> &Self { if let ThumbnailFormat::Tgs(t) = self { fnc(t) }; self }
101  pub fn on_webp<F: FnOnce(&ThumbnailFormatWebp)>(&self, fnc: F) -> &Self { if let ThumbnailFormat::Webp(t) = self { fnc(t) }; self }
102
103  pub fn as_gif(&self) -> Option<&ThumbnailFormatGif> { if let ThumbnailFormat::Gif(t) = self { return Some(t) } None }
104  pub fn as_jpeg(&self) -> Option<&ThumbnailFormatJpeg> { if let ThumbnailFormat::Jpeg(t) = self { return Some(t) } None }
105  pub fn as_mpeg4(&self) -> Option<&ThumbnailFormatMpeg4> { if let ThumbnailFormat::Mpeg4(t) = self { return Some(t) } None }
106  pub fn as_png(&self) -> Option<&ThumbnailFormatPng> { if let ThumbnailFormat::Png(t) = self { return Some(t) } None }
107  pub fn as_tgs(&self) -> Option<&ThumbnailFormatTgs> { if let ThumbnailFormat::Tgs(t) = self { return Some(t) } None }
108  pub fn as_webp(&self) -> Option<&ThumbnailFormatWebp> { if let ThumbnailFormat::Webp(t) = self { return Some(t) } None }
109
110
111
112  pub fn gif<T: AsRef<ThumbnailFormatGif>>(t: T) -> Self { ThumbnailFormat::Gif(t.as_ref().clone()) }
113
114  pub fn jpeg<T: AsRef<ThumbnailFormatJpeg>>(t: T) -> Self { ThumbnailFormat::Jpeg(t.as_ref().clone()) }
115
116  pub fn mpeg4<T: AsRef<ThumbnailFormatMpeg4>>(t: T) -> Self { ThumbnailFormat::Mpeg4(t.as_ref().clone()) }
117
118  pub fn png<T: AsRef<ThumbnailFormatPng>>(t: T) -> Self { ThumbnailFormat::Png(t.as_ref().clone()) }
119
120  pub fn tgs<T: AsRef<ThumbnailFormatTgs>>(t: T) -> Self { ThumbnailFormat::Tgs(t.as_ref().clone()) }
121
122  pub fn webp<T: AsRef<ThumbnailFormatWebp>>(t: T) -> Self { ThumbnailFormat::Webp(t.as_ref().clone()) }
123
124}
125
126impl AsRef<ThumbnailFormat> for ThumbnailFormat {
127  fn as_ref(&self) -> &ThumbnailFormat { self }
128}
129
130
131
132
133
134
135
136/// The thumbnail is in static GIF format. It will be used only for some bot inline results
137#[derive(Debug, Clone, Default, Serialize, Deserialize)]
138pub struct ThumbnailFormatGif {
139  #[doc(hidden)]
140  #[serde(rename(serialize = "@type", deserialize = "@type"))]
141  td_name: String,
142  #[doc(hidden)]
143  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
144  extra: Option<String>,
145  
146}
147
148impl RObject for ThumbnailFormatGif {
149  #[doc(hidden)] fn td_name(&self) -> &'static str { "thumbnailFormatGif" }
150  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
151  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
152}
153
154
155impl TDThumbnailFormat for ThumbnailFormatGif {}
156
157
158
159impl ThumbnailFormatGif {
160  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
161  pub fn builder() -> RTDThumbnailFormatGifBuilder {
162    let mut inner = ThumbnailFormatGif::default();
163    inner.td_name = "thumbnailFormatGif".to_string();
164    inner.extra = Some(Uuid::new_v4().to_string());
165    RTDThumbnailFormatGifBuilder { inner }
166  }
167
168}
169
170#[doc(hidden)]
171pub struct RTDThumbnailFormatGifBuilder {
172  inner: ThumbnailFormatGif
173}
174
175impl RTDThumbnailFormatGifBuilder {
176  pub fn build(&self) -> ThumbnailFormatGif { self.inner.clone() }
177
178}
179
180impl AsRef<ThumbnailFormatGif> for ThumbnailFormatGif {
181  fn as_ref(&self) -> &ThumbnailFormatGif { self }
182}
183
184impl AsRef<ThumbnailFormatGif> for RTDThumbnailFormatGifBuilder {
185  fn as_ref(&self) -> &ThumbnailFormatGif { &self.inner }
186}
187
188
189
190
191
192
193
194/// The thumbnail is in JPEG format
195#[derive(Debug, Clone, Default, Serialize, Deserialize)]
196pub struct ThumbnailFormatJpeg {
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  
204}
205
206impl RObject for ThumbnailFormatJpeg {
207  #[doc(hidden)] fn td_name(&self) -> &'static str { "thumbnailFormatJpeg" }
208  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
209  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
210}
211
212
213impl TDThumbnailFormat for ThumbnailFormatJpeg {}
214
215
216
217impl ThumbnailFormatJpeg {
218  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
219  pub fn builder() -> RTDThumbnailFormatJpegBuilder {
220    let mut inner = ThumbnailFormatJpeg::default();
221    inner.td_name = "thumbnailFormatJpeg".to_string();
222    inner.extra = Some(Uuid::new_v4().to_string());
223    RTDThumbnailFormatJpegBuilder { inner }
224  }
225
226}
227
228#[doc(hidden)]
229pub struct RTDThumbnailFormatJpegBuilder {
230  inner: ThumbnailFormatJpeg
231}
232
233impl RTDThumbnailFormatJpegBuilder {
234  pub fn build(&self) -> ThumbnailFormatJpeg { self.inner.clone() }
235
236}
237
238impl AsRef<ThumbnailFormatJpeg> for ThumbnailFormatJpeg {
239  fn as_ref(&self) -> &ThumbnailFormatJpeg { self }
240}
241
242impl AsRef<ThumbnailFormatJpeg> for RTDThumbnailFormatJpegBuilder {
243  fn as_ref(&self) -> &ThumbnailFormatJpeg { &self.inner }
244}
245
246
247
248
249
250
251
252/// The thumbnail is in MPEG4 format. It will be used only for some animations and videos
253#[derive(Debug, Clone, Default, Serialize, Deserialize)]
254pub struct ThumbnailFormatMpeg4 {
255  #[doc(hidden)]
256  #[serde(rename(serialize = "@type", deserialize = "@type"))]
257  td_name: String,
258  #[doc(hidden)]
259  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
260  extra: Option<String>,
261  
262}
263
264impl RObject for ThumbnailFormatMpeg4 {
265  #[doc(hidden)] fn td_name(&self) -> &'static str { "thumbnailFormatMpeg4" }
266  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
267  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
268}
269
270
271impl TDThumbnailFormat for ThumbnailFormatMpeg4 {}
272
273
274
275impl ThumbnailFormatMpeg4 {
276  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
277  pub fn builder() -> RTDThumbnailFormatMpeg4Builder {
278    let mut inner = ThumbnailFormatMpeg4::default();
279    inner.td_name = "thumbnailFormatMpeg4".to_string();
280    inner.extra = Some(Uuid::new_v4().to_string());
281    RTDThumbnailFormatMpeg4Builder { inner }
282  }
283
284}
285
286#[doc(hidden)]
287pub struct RTDThumbnailFormatMpeg4Builder {
288  inner: ThumbnailFormatMpeg4
289}
290
291impl RTDThumbnailFormatMpeg4Builder {
292  pub fn build(&self) -> ThumbnailFormatMpeg4 { self.inner.clone() }
293
294}
295
296impl AsRef<ThumbnailFormatMpeg4> for ThumbnailFormatMpeg4 {
297  fn as_ref(&self) -> &ThumbnailFormatMpeg4 { self }
298}
299
300impl AsRef<ThumbnailFormatMpeg4> for RTDThumbnailFormatMpeg4Builder {
301  fn as_ref(&self) -> &ThumbnailFormatMpeg4 { &self.inner }
302}
303
304
305
306
307
308
309
310/// The thumbnail is in PNG format. It will be used only for background patterns
311#[derive(Debug, Clone, Default, Serialize, Deserialize)]
312pub struct ThumbnailFormatPng {
313  #[doc(hidden)]
314  #[serde(rename(serialize = "@type", deserialize = "@type"))]
315  td_name: String,
316  #[doc(hidden)]
317  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
318  extra: Option<String>,
319  
320}
321
322impl RObject for ThumbnailFormatPng {
323  #[doc(hidden)] fn td_name(&self) -> &'static str { "thumbnailFormatPng" }
324  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
325  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
326}
327
328
329impl TDThumbnailFormat for ThumbnailFormatPng {}
330
331
332
333impl ThumbnailFormatPng {
334  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
335  pub fn builder() -> RTDThumbnailFormatPngBuilder {
336    let mut inner = ThumbnailFormatPng::default();
337    inner.td_name = "thumbnailFormatPng".to_string();
338    inner.extra = Some(Uuid::new_v4().to_string());
339    RTDThumbnailFormatPngBuilder { inner }
340  }
341
342}
343
344#[doc(hidden)]
345pub struct RTDThumbnailFormatPngBuilder {
346  inner: ThumbnailFormatPng
347}
348
349impl RTDThumbnailFormatPngBuilder {
350  pub fn build(&self) -> ThumbnailFormatPng { self.inner.clone() }
351
352}
353
354impl AsRef<ThumbnailFormatPng> for ThumbnailFormatPng {
355  fn as_ref(&self) -> &ThumbnailFormatPng { self }
356}
357
358impl AsRef<ThumbnailFormatPng> for RTDThumbnailFormatPngBuilder {
359  fn as_ref(&self) -> &ThumbnailFormatPng { &self.inner }
360}
361
362
363
364
365
366
367
368/// The thumbnail is in TGS format. It will be used only for animated sticker sets
369#[derive(Debug, Clone, Default, Serialize, Deserialize)]
370pub struct ThumbnailFormatTgs {
371  #[doc(hidden)]
372  #[serde(rename(serialize = "@type", deserialize = "@type"))]
373  td_name: String,
374  #[doc(hidden)]
375  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
376  extra: Option<String>,
377  
378}
379
380impl RObject for ThumbnailFormatTgs {
381  #[doc(hidden)] fn td_name(&self) -> &'static str { "thumbnailFormatTgs" }
382  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
383  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
384}
385
386
387impl TDThumbnailFormat for ThumbnailFormatTgs {}
388
389
390
391impl ThumbnailFormatTgs {
392  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
393  pub fn builder() -> RTDThumbnailFormatTgsBuilder {
394    let mut inner = ThumbnailFormatTgs::default();
395    inner.td_name = "thumbnailFormatTgs".to_string();
396    inner.extra = Some(Uuid::new_v4().to_string());
397    RTDThumbnailFormatTgsBuilder { inner }
398  }
399
400}
401
402#[doc(hidden)]
403pub struct RTDThumbnailFormatTgsBuilder {
404  inner: ThumbnailFormatTgs
405}
406
407impl RTDThumbnailFormatTgsBuilder {
408  pub fn build(&self) -> ThumbnailFormatTgs { self.inner.clone() }
409
410}
411
412impl AsRef<ThumbnailFormatTgs> for ThumbnailFormatTgs {
413  fn as_ref(&self) -> &ThumbnailFormatTgs { self }
414}
415
416impl AsRef<ThumbnailFormatTgs> for RTDThumbnailFormatTgsBuilder {
417  fn as_ref(&self) -> &ThumbnailFormatTgs { &self.inner }
418}
419
420
421
422
423
424
425
426/// The thumbnail is in WEBP format. It will be used only for some stickers
427#[derive(Debug, Clone, Default, Serialize, Deserialize)]
428pub struct ThumbnailFormatWebp {
429  #[doc(hidden)]
430  #[serde(rename(serialize = "@type", deserialize = "@type"))]
431  td_name: String,
432  #[doc(hidden)]
433  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
434  extra: Option<String>,
435  
436}
437
438impl RObject for ThumbnailFormatWebp {
439  #[doc(hidden)] fn td_name(&self) -> &'static str { "thumbnailFormatWebp" }
440  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
441  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
442}
443
444
445impl TDThumbnailFormat for ThumbnailFormatWebp {}
446
447
448
449impl ThumbnailFormatWebp {
450  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
451  pub fn builder() -> RTDThumbnailFormatWebpBuilder {
452    let mut inner = ThumbnailFormatWebp::default();
453    inner.td_name = "thumbnailFormatWebp".to_string();
454    inner.extra = Some(Uuid::new_v4().to_string());
455    RTDThumbnailFormatWebpBuilder { inner }
456  }
457
458}
459
460#[doc(hidden)]
461pub struct RTDThumbnailFormatWebpBuilder {
462  inner: ThumbnailFormatWebp
463}
464
465impl RTDThumbnailFormatWebpBuilder {
466  pub fn build(&self) -> ThumbnailFormatWebp { self.inner.clone() }
467
468}
469
470impl AsRef<ThumbnailFormatWebp> for ThumbnailFormatWebp {
471  fn as_ref(&self) -> &ThumbnailFormatWebp { self }
472}
473
474impl AsRef<ThumbnailFormatWebp> for RTDThumbnailFormatWebpBuilder {
475  fn as_ref(&self) -> &ThumbnailFormatWebp { &self.inner }
476}
477
478
479