rtdlib 1.8.69

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
use crate::errors::*;
use crate::types::*;
use uuid::Uuid;

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

/// TRAIT | Describes state of an auction
pub trait TDAuctionState: Debug + RObject {}

/// Describes state of an auction
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum AuctionState {
  #[doc(hidden)]
  _Default(()),
  /// Contains information about an ongoing or scheduled auction
  Active(AuctionStateActive),
  /// Contains information about a finished auction
  Finished(AuctionStateFinished),
}

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

impl<'de> Deserialize<'de> for AuctionState {
  fn deserialize<D>(deserializer: D) -> Result<AuctionState, D::Error>
  where
    D: Deserializer<'de>,
  {
    use serde::de::Error;
    rtd_enum_deserialize!(
      AuctionState,
      (auctionStateActive, Active);
      (auctionStateFinished, Finished);

    )(deserializer)
  }
}

impl RObject for AuctionState {
  #[doc(hidden)]
  fn td_name(&self) -> &'static str {
    match self {
      AuctionState::Active(t) => t.td_name(),
      AuctionState::Finished(t) => t.td_name(),

      _ => "-1",
    }
  }
  #[doc(hidden)]
  fn extra(&self) -> Option<String> {
    match self {
      AuctionState::Active(t) => t.extra(),
      AuctionState::Finished(t) => t.extra(),

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

impl AuctionState {
  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, AuctionState::_Default(_))
  }

  pub fn is_active(&self) -> bool {
    matches!(self, AuctionState::Active(_))
  }
  pub fn is_finished(&self) -> bool {
    matches!(self, AuctionState::Finished(_))
  }

  pub fn on_active<F: FnOnce(&AuctionStateActive)>(&self, fnc: F) -> &Self {
    if let AuctionState::Active(t) = self {
      fnc(t)
    };
    self
  }
  pub fn on_finished<F: FnOnce(&AuctionStateFinished)>(&self, fnc: F) -> &Self {
    if let AuctionState::Finished(t) = self {
      fnc(t)
    };
    self
  }

  pub fn as_active(&self) -> Option<&AuctionStateActive> {
    if let AuctionState::Active(t) = self {
      return Some(t);
    }
    None
  }
  pub fn as_finished(&self) -> Option<&AuctionStateFinished> {
    if let AuctionState::Finished(t) = self {
      return Some(t);
    }
    None
  }

  pub fn active<T: AsRef<AuctionStateActive>>(t: T) -> Self {
    AuctionState::Active(t.as_ref().clone())
  }

  pub fn finished<T: AsRef<AuctionStateFinished>>(t: T) -> Self {
    AuctionState::Finished(t.as_ref().clone())
  }
}

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

/// Contains information about an ongoing or scheduled auction
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct AuctionStateActive {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Point in time (Unix timestamp) when the auction started or will start
  start_date: i64,
  /// Point in time (Unix timestamp) when the auction will be ended
  end_date: i64,
  /// The minimum possible bid in the auction in Telegram Stars
  min_bid: i64,
  /// A sparse list of bids that were made in the auction
  bid_levels: Vec<AuctionBid>,
  /// User identifiers of at most 3 users with the biggest bids
  top_bidder_user_ids: Vec<i64>,
  /// Rounds of the auction in which their duration or extension rules are changed
  rounds: Vec<AuctionRound>,
  /// Point in time (Unix timestamp) when the current round will end
  current_round_end_date: i64,
  /// 1-based number of the current round
  current_round_number: i64,
  /// The total number of rounds
  total_round_count: i64,
  /// The number of items that were purchased on the auction by all users
  distributed_item_count: i64,
  /// The number of items that have to be distributed on the auction
  left_item_count: i64,
  /// The number of items that were purchased by the current user on the auction
  acquired_item_count: i64,
  /// Bid of the current user in the auction; may be null if none
  user_bid: Option<UserAuctionBid>,
}

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

impl TDAuctionState for AuctionStateActive {}

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

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

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

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

  pub fn bid_levels(&self) -> &Vec<AuctionBid> {
    &self.bid_levels
  }

  pub fn top_bidder_user_ids(&self) -> &Vec<i64> {
    &self.top_bidder_user_ids
  }

  pub fn rounds(&self) -> &Vec<AuctionRound> {
    &self.rounds
  }

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

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

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

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

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

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

  pub fn user_bid(&self) -> &Option<UserAuctionBid> {
    &self.user_bid
  }
}

#[doc(hidden)]
pub struct RTDAuctionStateActiveBuilder {
  inner: AuctionStateActive,
}

impl RTDAuctionStateActiveBuilder {
  pub fn build(&self) -> AuctionStateActive {
    self.inner.clone()
  }

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

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

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

  pub fn bid_levels(&mut self, bid_levels: Vec<AuctionBid>) -> &mut Self {
    self.inner.bid_levels = bid_levels;
    self
  }

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

  pub fn rounds(&mut self, rounds: Vec<AuctionRound>) -> &mut Self {
    self.inner.rounds = rounds;
    self
  }

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

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

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

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

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

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

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

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

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

/// Contains information about a finished auction
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct AuctionStateFinished {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Point in time (Unix timestamp) when the auction started
  start_date: i64,
  /// Point in time (Unix timestamp) when the auction will be ended
  end_date: i64,
  /// Average price of bought items in Telegram Stars
  average_price: i64,
  /// The number of items that were purchased by the current user on the auction
  acquired_item_count: i64,
  /// Number of items from the auction being resold on Telegram
  telegram_listed_item_count: i64,
  /// Number of items from the auction being resold on Fragment
  fragment_listed_item_count: i64,
  /// The HTTPS link to the Fragment for the resold items; may be empty if there are no such items being sold on Fragment
  fragment_url: String,
}

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

impl TDAuctionState for AuctionStateFinished {}

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

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

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

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

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

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

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

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

#[doc(hidden)]
pub struct RTDAuctionStateFinishedBuilder {
  inner: AuctionStateFinished,
}

impl RTDAuctionStateFinishedBuilder {
  pub fn build(&self) -> AuctionStateFinished {
    self.inner.clone()
  }

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

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

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

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

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

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

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

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

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