rust_tdlib/types/
thumbnail_format.rs

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