rtdlib 1.8.70

TDLib for rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
use crate::errors::*;
use crate::types::*;
use uuid::Uuid;

use serde::de::{Deserialize, Deserializer};
use std::fmt::Debug;

/// TRAIT | Describes the type of background
pub trait TDBackgroundType: Debug + RObject {}

/// Describes the type of background
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum BackgroundType {
  #[doc(hidden)]
  _Default(()),
  /// A background from a chat theme based on an emoji; can be used only as a chat background in channels
  ChatTheme(BackgroundTypeChatTheme),
  /// A filled background
  Fill(BackgroundTypeFill),
  /// A PNG or TGV (gzipped subset of SVG with MIME type "application/x-tgwallpattern") pattern to be combined with the background fill chosen by the user
  Pattern(BackgroundTypePattern),
  /// A wallpaper in JPEG format
  Wallpaper(BackgroundTypeWallpaper),
}

impl Default for BackgroundType {
  fn default() -> Self {
    BackgroundType::_Default(())
  }
}

impl<'de> Deserialize<'de> for BackgroundType {
  fn deserialize<D>(deserializer: D) -> Result<BackgroundType, D::Error>
  where
    D: Deserializer<'de>,
  {
    use serde::de::Error;
    rtd_enum_deserialize!(
      BackgroundType,
      (backgroundTypeChatTheme, ChatTheme);
      (backgroundTypeFill, Fill);
      (backgroundTypePattern, Pattern);
      (backgroundTypeWallpaper, Wallpaper);

    )(deserializer)
  }
}

impl RObject for BackgroundType {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    match self {
      BackgroundType::ChatTheme(t) => t.td_name(),
      BackgroundType::Fill(t) => t.td_name(),
      BackgroundType::Pattern(t) => t.td_name(),
      BackgroundType::Wallpaper(t) => t.td_name(),

      _ => "-1",
    }
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    match self {
      BackgroundType::ChatTheme(t) => t.extra(),
      BackgroundType::Fill(t) => t.extra(),
      BackgroundType::Pattern(t) => t.extra(),
      BackgroundType::Wallpaper(t) => t.extra(),

      _ => None,
    }
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl BackgroundType {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  #[doc(hidden)]
  pub fn _is_default(&self) -> bool {
    matches!(self, BackgroundType::_Default(_))
  }

  pub fn is_chat_theme(&self) -> bool {
    matches!(self, BackgroundType::ChatTheme(_))
  }
  pub fn is_fill(&self) -> bool {
    matches!(self, BackgroundType::Fill(_))
  }
  pub fn is_pattern(&self) -> bool {
    matches!(self, BackgroundType::Pattern(_))
  }
  pub fn is_wallpaper(&self) -> bool {
    matches!(self, BackgroundType::Wallpaper(_))
  }

  pub fn on_chat_theme<F: FnOnce(&BackgroundTypeChatTheme)>(&self, fnc: F) -> &Self {
    if let BackgroundType::ChatTheme(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_fill<F: FnOnce(&BackgroundTypeFill)>(&self, fnc: F) -> &Self {
    if let BackgroundType::Fill(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_pattern<F: FnOnce(&BackgroundTypePattern)>(&self, fnc: F) -> &Self {
    if let BackgroundType::Pattern(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_wallpaper<F: FnOnce(&BackgroundTypeWallpaper)>(&self, fnc: F) -> &Self {
    if let BackgroundType::Wallpaper(t) = self {
      fnc(t)
    };
    self
  }

  pub fn as_chat_theme(&self) -> Option<&BackgroundTypeChatTheme> {
    if let BackgroundType::ChatTheme(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_fill(&self) -> Option<&BackgroundTypeFill> {
    if let BackgroundType::Fill(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_pattern(&self) -> Option<&BackgroundTypePattern> {
    if let BackgroundType::Pattern(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_wallpaper(&self) -> Option<&BackgroundTypeWallpaper> {
    if let BackgroundType::Wallpaper(t) = self {
      return Some(t);
    }
    None
  }

  pub fn chat_theme<T: AsRef<BackgroundTypeChatTheme>>(t: T) -> Self {
    BackgroundType::ChatTheme(t.as_ref().clone())
  }

  pub fn fill<T: AsRef<BackgroundTypeFill>>(t: T) -> Self {
    BackgroundType::Fill(t.as_ref().clone())
  }

  pub fn pattern<T: AsRef<BackgroundTypePattern>>(t: T) -> Self {
    BackgroundType::Pattern(t.as_ref().clone())
  }

  pub fn wallpaper<T: AsRef<BackgroundTypeWallpaper>>(t: T) -> Self {
    BackgroundType::Wallpaper(t.as_ref().clone())
  }
}

impl AsRef<BackgroundType> for BackgroundType {
  fn as_ref(&self) -> &BackgroundType {
    self
  }
}

/// A background from a chat theme based on an emoji; can be used only as a chat background in channels
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundTypeChatTheme {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Name of the emoji chat theme
  theme_name: String,
}

impl RObject for BackgroundTypeChatTheme {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "backgroundTypeChatTheme"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDBackgroundType for BackgroundTypeChatTheme {}

impl BackgroundTypeChatTheme {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDBackgroundTypeChatThemeBuilder {
    let inner = BackgroundTypeChatTheme {
      td_name: "backgroundTypeChatTheme".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDBackgroundTypeChatThemeBuilder { inner }
  }

  pub fn theme_name(&self) -> &String {
    &self.theme_name
  }
}

#[doc(hidden)]
pub struct RTDBackgroundTypeChatThemeBuilder {
  inner: BackgroundTypeChatTheme,
}

impl RTDBackgroundTypeChatThemeBuilder {
  pub fn build(&self) -> BackgroundTypeChatTheme {
    self.inner.clone()
  }

  pub fn theme_name<T: AsRef<str>>(&mut self, theme_name: T) -> &mut Self {
    self.inner.theme_name = theme_name.as_ref().to_string();
    self
  }
}

impl AsRef<BackgroundTypeChatTheme> for BackgroundTypeChatTheme {
  fn as_ref(&self) -> &BackgroundTypeChatTheme {
    self
  }
}

impl AsRef<BackgroundTypeChatTheme> for RTDBackgroundTypeChatThemeBuilder {
  fn as_ref(&self) -> &BackgroundTypeChatTheme {
    &self.inner
  }
}

/// A filled background
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundTypeFill {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// The background fill
  fill: BackgroundFill,
}

impl RObject for BackgroundTypeFill {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "backgroundTypeFill"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDBackgroundType for BackgroundTypeFill {}

impl BackgroundTypeFill {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDBackgroundTypeFillBuilder {
    let inner = BackgroundTypeFill {
      td_name: "backgroundTypeFill".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDBackgroundTypeFillBuilder { inner }
  }

  pub fn fill(&self) -> &BackgroundFill {
    &self.fill
  }
}

#[doc(hidden)]
pub struct RTDBackgroundTypeFillBuilder {
  inner: BackgroundTypeFill,
}

impl RTDBackgroundTypeFillBuilder {
  pub fn build(&self) -> BackgroundTypeFill {
    self.inner.clone()
  }

  pub fn fill<T: AsRef<BackgroundFill>>(&mut self, fill: T) -> &mut Self {
    self.inner.fill = fill.as_ref().clone();
    self
  }
}

impl AsRef<BackgroundTypeFill> for BackgroundTypeFill {
  fn as_ref(&self) -> &BackgroundTypeFill {
    self
  }
}

impl AsRef<BackgroundTypeFill> for RTDBackgroundTypeFillBuilder {
  fn as_ref(&self) -> &BackgroundTypeFill {
    &self.inner
  }
}

/// A PNG or TGV (gzipped subset of SVG with MIME type "application/x-tgwallpattern") pattern to be combined with the background fill chosen by the user
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundTypePattern {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Fill of the background
  fill: BackgroundFill,
  /// Intensity of the pattern when it is shown above the filled background; 0-100
  intensity: i64,
  /// True, if the background fill must be applied only to the pattern itself. All other pixels are black in this case. For dark themes only
  is_inverted: bool,
  /// True, if the background needs to be slightly moved when device is tilted
  is_moving: bool,
}

impl RObject for BackgroundTypePattern {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "backgroundTypePattern"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDBackgroundType for BackgroundTypePattern {}

impl BackgroundTypePattern {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDBackgroundTypePatternBuilder {
    let inner = BackgroundTypePattern {
      td_name: "backgroundTypePattern".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDBackgroundTypePatternBuilder { inner }
  }

  pub fn fill(&self) -> &BackgroundFill {
    &self.fill
  }

  pub fn intensity(&self) -> i64 {
    self.intensity
  }

  pub fn is_inverted(&self) -> bool {
    self.is_inverted
  }

  pub fn is_moving(&self) -> bool {
    self.is_moving
  }
}

#[doc(hidden)]
pub struct RTDBackgroundTypePatternBuilder {
  inner: BackgroundTypePattern,
}

impl RTDBackgroundTypePatternBuilder {
  pub fn build(&self) -> BackgroundTypePattern {
    self.inner.clone()
  }

  pub fn fill<T: AsRef<BackgroundFill>>(&mut self, fill: T) -> &mut Self {
    self.inner.fill = fill.as_ref().clone();
    self
  }

  pub fn intensity(&mut self, intensity: i64) -> &mut Self {
    self.inner.intensity = intensity;
    self
  }

  pub fn is_inverted(&mut self, is_inverted: bool) -> &mut Self {
    self.inner.is_inverted = is_inverted;
    self
  }

  pub fn is_moving(&mut self, is_moving: bool) -> &mut Self {
    self.inner.is_moving = is_moving;
    self
  }
}

impl AsRef<BackgroundTypePattern> for BackgroundTypePattern {
  fn as_ref(&self) -> &BackgroundTypePattern {
    self
  }
}

impl AsRef<BackgroundTypePattern> for RTDBackgroundTypePatternBuilder {
  fn as_ref(&self) -> &BackgroundTypePattern {
    &self.inner
  }
}

/// A wallpaper in JPEG format
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct BackgroundTypeWallpaper {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// True, if the wallpaper must be downscaled to fit in 450x450 square and then box-blurred with radius 12
  is_blurred: bool,
  /// True, if the background needs to be slightly moved when device is tilted
  is_moving: bool,
}

impl RObject for BackgroundTypeWallpaper {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    "backgroundTypeWallpaper"
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    self.extra.clone()
  }
  fn to_json(&self) -> RTDResult<String> {
    Ok(serde_json::to_string(self)?)
  }
}

impl TDBackgroundType for BackgroundTypeWallpaper {}

impl BackgroundTypeWallpaper {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> {
    Ok(serde_json::from_str(json.as_ref())?)
  }
  pub fn builder() -> RTDBackgroundTypeWallpaperBuilder {
    let inner = BackgroundTypeWallpaper {
      td_name: "backgroundTypeWallpaper".to_string(),
      extra: Some(Uuid::new_v4().to_string()),
      ..Default::default()
    };
    RTDBackgroundTypeWallpaperBuilder { inner }
  }

  pub fn is_blurred(&self) -> bool {
    self.is_blurred
  }

  pub fn is_moving(&self) -> bool {
    self.is_moving
  }
}

#[doc(hidden)]
pub struct RTDBackgroundTypeWallpaperBuilder {
  inner: BackgroundTypeWallpaper,
}

impl RTDBackgroundTypeWallpaperBuilder {
  pub fn build(&self) -> BackgroundTypeWallpaper {
    self.inner.clone()
  }

  pub fn is_blurred(&mut self, is_blurred: bool) -> &mut Self {
    self.inner.is_blurred = is_blurred;
    self
  }

  pub fn is_moving(&mut self, is_moving: bool) -> &mut Self {
    self.inner.is_moving = is_moving;
    self
  }
}

impl AsRef<BackgroundTypeWallpaper> for BackgroundTypeWallpaper {
  fn as_ref(&self) -> &BackgroundTypeWallpaper {
    self
  }
}

impl AsRef<BackgroundTypeWallpaper> for RTDBackgroundTypeWallpaperBuilder {
  fn as_ref(&self) -> &BackgroundTypeWallpaper {
    &self.inner
  }
}