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
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
use std::fmt::{Debug, Display};
use std::str::FromStr;

use serde::{
    de::{Deserialize, Deserializer, Error as SerdeDeError},
    ser::{Serialize, Serializer},
};

use crate::{errors::*, types::*};

#[allow(dead_code)]
pub fn from_json<'a, T>(json: &'a str) -> Result<T>
where
    T: Deserialize<'a>,
{
    Ok(serde_json::from_str(json)?)
}

/// All tdlib type abstract class defined the same behavior
pub trait RObject: Debug {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str>;
    fn client_id(&self) -> Option<i32>;
}

pub trait RFunction: Debug + RObject + Serialize {
    fn to_json(&self) -> Result<String> {
        Ok(serde_json::to_string(self)?)
    }
}

impl<'a, RObj: RObject> RObject for &'a RObj {
    fn extra(&self) -> Option<&str> {
        (*self).extra()
    }
    fn client_id(&self) -> Option<i32> {
        (*self).client_id()
    }
}

impl<'a, RObj: RObject> RObject for &'a mut RObj {
    fn extra(&self) -> Option<&str> {
        (**self).extra()
    }
    fn client_id(&self) -> Option<i32> {
        (**self).client_id()
    }
}

impl<'a, Fnc: RFunction> RFunction for &'a Fnc {}
impl<'a, Fnc: RFunction> RFunction for &'a mut Fnc {}

impl<'a, AUTHENTICATIONCODETYPE: TDAuthenticationCodeType> TDAuthenticationCodeType
    for &'a AUTHENTICATIONCODETYPE
{
}
impl<'a, AUTHENTICATIONCODETYPE: TDAuthenticationCodeType> TDAuthenticationCodeType
    for &'a mut AUTHENTICATIONCODETYPE
{
}

impl<'a, AUTHORIZATIONSTATE: TDAuthorizationState> TDAuthorizationState for &'a AUTHORIZATIONSTATE {}
impl<'a, AUTHORIZATIONSTATE: TDAuthorizationState> TDAuthorizationState
    for &'a mut AUTHORIZATIONSTATE
{
}

impl<'a, BACKGROUNDFILL: TDBackgroundFill> TDBackgroundFill for &'a BACKGROUNDFILL {}
impl<'a, BACKGROUNDFILL: TDBackgroundFill> TDBackgroundFill for &'a mut BACKGROUNDFILL {}

impl<'a, BACKGROUNDTYPE: TDBackgroundType> TDBackgroundType for &'a BACKGROUNDTYPE {}
impl<'a, BACKGROUNDTYPE: TDBackgroundType> TDBackgroundType for &'a mut BACKGROUNDTYPE {}

impl<'a, BOTCOMMANDSCOPE: TDBotCommandScope> TDBotCommandScope for &'a BOTCOMMANDSCOPE {}
impl<'a, BOTCOMMANDSCOPE: TDBotCommandScope> TDBotCommandScope for &'a mut BOTCOMMANDSCOPE {}

impl<'a, CALLDISCARDREASON: TDCallDiscardReason> TDCallDiscardReason for &'a CALLDISCARDREASON {}
impl<'a, CALLDISCARDREASON: TDCallDiscardReason> TDCallDiscardReason for &'a mut CALLDISCARDREASON {}

impl<'a, CALLPROBLEM: TDCallProblem> TDCallProblem for &'a CALLPROBLEM {}
impl<'a, CALLPROBLEM: TDCallProblem> TDCallProblem for &'a mut CALLPROBLEM {}

impl<'a, CALLSERVERTYPE: TDCallServerType> TDCallServerType for &'a CALLSERVERTYPE {}
impl<'a, CALLSERVERTYPE: TDCallServerType> TDCallServerType for &'a mut CALLSERVERTYPE {}

impl<'a, CALLSTATE: TDCallState> TDCallState for &'a CALLSTATE {}
impl<'a, CALLSTATE: TDCallState> TDCallState for &'a mut CALLSTATE {}

impl<'a, CALLBACKQUERYPAYLOAD: TDCallbackQueryPayload> TDCallbackQueryPayload
    for &'a CALLBACKQUERYPAYLOAD
{
}
impl<'a, CALLBACKQUERYPAYLOAD: TDCallbackQueryPayload> TDCallbackQueryPayload
    for &'a mut CALLBACKQUERYPAYLOAD
{
}

impl<'a, CANTRANSFEROWNERSHIPRESULT: TDCanTransferOwnershipResult> TDCanTransferOwnershipResult
    for &'a CANTRANSFEROWNERSHIPRESULT
{
}
impl<'a, CANTRANSFEROWNERSHIPRESULT: TDCanTransferOwnershipResult> TDCanTransferOwnershipResult
    for &'a mut CANTRANSFEROWNERSHIPRESULT
{
}

impl<'a, CHATACTION: TDChatAction> TDChatAction for &'a CHATACTION {}
impl<'a, CHATACTION: TDChatAction> TDChatAction for &'a mut CHATACTION {}

impl<'a, CHATACTIONBAR: TDChatActionBar> TDChatActionBar for &'a CHATACTIONBAR {}
impl<'a, CHATACTIONBAR: TDChatActionBar> TDChatActionBar for &'a mut CHATACTIONBAR {}

impl<'a, CHATEVENTACTION: TDChatEventAction> TDChatEventAction for &'a CHATEVENTACTION {}
impl<'a, CHATEVENTACTION: TDChatEventAction> TDChatEventAction for &'a mut CHATEVENTACTION {}

impl<'a, CHATLIST: TDChatList> TDChatList for &'a CHATLIST {}
impl<'a, CHATLIST: TDChatList> TDChatList for &'a mut CHATLIST {}

impl<'a, CHATMEMBERSTATUS: TDChatMemberStatus> TDChatMemberStatus for &'a CHATMEMBERSTATUS {}
impl<'a, CHATMEMBERSTATUS: TDChatMemberStatus> TDChatMemberStatus for &'a mut CHATMEMBERSTATUS {}

impl<'a, CHATMEMBERSFILTER: TDChatMembersFilter> TDChatMembersFilter for &'a CHATMEMBERSFILTER {}
impl<'a, CHATMEMBERSFILTER: TDChatMembersFilter> TDChatMembersFilter for &'a mut CHATMEMBERSFILTER {}

impl<'a, CHATREPORTREASON: TDChatReportReason> TDChatReportReason for &'a CHATREPORTREASON {}
impl<'a, CHATREPORTREASON: TDChatReportReason> TDChatReportReason for &'a mut CHATREPORTREASON {}

impl<'a, CHATSOURCE: TDChatSource> TDChatSource for &'a CHATSOURCE {}
impl<'a, CHATSOURCE: TDChatSource> TDChatSource for &'a mut CHATSOURCE {}

impl<'a, CHATSTATISTICS: TDChatStatistics> TDChatStatistics for &'a CHATSTATISTICS {}
impl<'a, CHATSTATISTICS: TDChatStatistics> TDChatStatistics for &'a mut CHATSTATISTICS {}

impl<'a, CHATTYPE: TDChatType> TDChatType for &'a CHATTYPE {}
impl<'a, CHATTYPE: TDChatType> TDChatType for &'a mut CHATTYPE {}

impl<'a, CHECKCHATUSERNAMERESULT: TDCheckChatUsernameResult> TDCheckChatUsernameResult
    for &'a CHECKCHATUSERNAMERESULT
{
}
impl<'a, CHECKCHATUSERNAMERESULT: TDCheckChatUsernameResult> TDCheckChatUsernameResult
    for &'a mut CHECKCHATUSERNAMERESULT
{
}

impl<'a, CHECKSTICKERSETNAMERESULT: TDCheckStickerSetNameResult> TDCheckStickerSetNameResult
    for &'a CHECKSTICKERSETNAMERESULT
{
}
impl<'a, CHECKSTICKERSETNAMERESULT: TDCheckStickerSetNameResult> TDCheckStickerSetNameResult
    for &'a mut CHECKSTICKERSETNAMERESULT
{
}

impl<'a, CONNECTIONSTATE: TDConnectionState> TDConnectionState for &'a CONNECTIONSTATE {}
impl<'a, CONNECTIONSTATE: TDConnectionState> TDConnectionState for &'a mut CONNECTIONSTATE {}

impl<'a, DEVICETOKEN: TDDeviceToken> TDDeviceToken for &'a DEVICETOKEN {}
impl<'a, DEVICETOKEN: TDDeviceToken> TDDeviceToken for &'a mut DEVICETOKEN {}

impl<'a, DICESTICKERS: TDDiceStickers> TDDiceStickers for &'a DICESTICKERS {}
impl<'a, DICESTICKERS: TDDiceStickers> TDDiceStickers for &'a mut DICESTICKERS {}

impl<'a, FILETYPE: TDFileType> TDFileType for &'a FILETYPE {}
impl<'a, FILETYPE: TDFileType> TDFileType for &'a mut FILETYPE {}

impl<'a, GROUPCALLVIDEOQUALITY: TDGroupCallVideoQuality> TDGroupCallVideoQuality
    for &'a GROUPCALLVIDEOQUALITY
{
}
impl<'a, GROUPCALLVIDEOQUALITY: TDGroupCallVideoQuality> TDGroupCallVideoQuality
    for &'a mut GROUPCALLVIDEOQUALITY
{
}

impl<'a, INLINEKEYBOARDBUTTONTYPE: TDInlineKeyboardButtonType> TDInlineKeyboardButtonType
    for &'a INLINEKEYBOARDBUTTONTYPE
{
}
impl<'a, INLINEKEYBOARDBUTTONTYPE: TDInlineKeyboardButtonType> TDInlineKeyboardButtonType
    for &'a mut INLINEKEYBOARDBUTTONTYPE
{
}

impl<'a, INLINEQUERYRESULT: TDInlineQueryResult> TDInlineQueryResult for &'a INLINEQUERYRESULT {}
impl<'a, INLINEQUERYRESULT: TDInlineQueryResult> TDInlineQueryResult for &'a mut INLINEQUERYRESULT {}

impl<'a, INPUTBACKGROUND: TDInputBackground> TDInputBackground for &'a INPUTBACKGROUND {}
impl<'a, INPUTBACKGROUND: TDInputBackground> TDInputBackground for &'a mut INPUTBACKGROUND {}

impl<'a, INPUTCHATPHOTO: TDInputChatPhoto> TDInputChatPhoto for &'a INPUTCHATPHOTO {}
impl<'a, INPUTCHATPHOTO: TDInputChatPhoto> TDInputChatPhoto for &'a mut INPUTCHATPHOTO {}

impl<'a, INPUTCREDENTIALS: TDInputCredentials> TDInputCredentials for &'a INPUTCREDENTIALS {}
impl<'a, INPUTCREDENTIALS: TDInputCredentials> TDInputCredentials for &'a mut INPUTCREDENTIALS {}

impl<'a, INPUTFILE: TDInputFile> TDInputFile for &'a INPUTFILE {}
impl<'a, INPUTFILE: TDInputFile> TDInputFile for &'a mut INPUTFILE {}

impl<'a, INPUTINLINEQUERYRESULT: TDInputInlineQueryResult> TDInputInlineQueryResult
    for &'a INPUTINLINEQUERYRESULT
{
}
impl<'a, INPUTINLINEQUERYRESULT: TDInputInlineQueryResult> TDInputInlineQueryResult
    for &'a mut INPUTINLINEQUERYRESULT
{
}

impl<'a, INPUTMESSAGECONTENT: TDInputMessageContent> TDInputMessageContent
    for &'a INPUTMESSAGECONTENT
{
}
impl<'a, INPUTMESSAGECONTENT: TDInputMessageContent> TDInputMessageContent
    for &'a mut INPUTMESSAGECONTENT
{
}

impl<'a, INPUTPASSPORTELEMENT: TDInputPassportElement> TDInputPassportElement
    for &'a INPUTPASSPORTELEMENT
{
}
impl<'a, INPUTPASSPORTELEMENT: TDInputPassportElement> TDInputPassportElement
    for &'a mut INPUTPASSPORTELEMENT
{
}

impl<'a, INPUTPASSPORTELEMENTERRORSOURCE: TDInputPassportElementErrorSource>
    TDInputPassportElementErrorSource for &'a INPUTPASSPORTELEMENTERRORSOURCE
{
}
impl<'a, INPUTPASSPORTELEMENTERRORSOURCE: TDInputPassportElementErrorSource>
    TDInputPassportElementErrorSource for &'a mut INPUTPASSPORTELEMENTERRORSOURCE
{
}

impl<'a, INPUTSTICKER: TDInputSticker> TDInputSticker for &'a INPUTSTICKER {}
impl<'a, INPUTSTICKER: TDInputSticker> TDInputSticker for &'a mut INPUTSTICKER {}

impl<'a, INTERNALLINKTYPE: TDInternalLinkType> TDInternalLinkType for &'a INTERNALLINKTYPE {}
impl<'a, INTERNALLINKTYPE: TDInternalLinkType> TDInternalLinkType for &'a mut INTERNALLINKTYPE {}

impl<'a, JSONVALUE: TDJsonValue> TDJsonValue for &'a JSONVALUE {}
impl<'a, JSONVALUE: TDJsonValue> TDJsonValue for &'a mut JSONVALUE {}

impl<'a, KEYBOARDBUTTONTYPE: TDKeyboardButtonType> TDKeyboardButtonType for &'a KEYBOARDBUTTONTYPE {}
impl<'a, KEYBOARDBUTTONTYPE: TDKeyboardButtonType> TDKeyboardButtonType
    for &'a mut KEYBOARDBUTTONTYPE
{
}

impl<'a, LANGUAGEPACKSTRINGVALUE: TDLanguagePackStringValue> TDLanguagePackStringValue
    for &'a LANGUAGEPACKSTRINGVALUE
{
}
impl<'a, LANGUAGEPACKSTRINGVALUE: TDLanguagePackStringValue> TDLanguagePackStringValue
    for &'a mut LANGUAGEPACKSTRINGVALUE
{
}

impl<'a, LOGSTREAM: TDLogStream> TDLogStream for &'a LOGSTREAM {}
impl<'a, LOGSTREAM: TDLogStream> TDLogStream for &'a mut LOGSTREAM {}

impl<'a, LOGINURLINFO: TDLoginUrlInfo> TDLoginUrlInfo for &'a LOGINURLINFO {}
impl<'a, LOGINURLINFO: TDLoginUrlInfo> TDLoginUrlInfo for &'a mut LOGINURLINFO {}

impl<'a, MASKPOINT: TDMaskPoint> TDMaskPoint for &'a MASKPOINT {}
impl<'a, MASKPOINT: TDMaskPoint> TDMaskPoint for &'a mut MASKPOINT {}

impl<'a, MESSAGECONTENT: TDMessageContent> TDMessageContent for &'a MESSAGECONTENT {}
impl<'a, MESSAGECONTENT: TDMessageContent> TDMessageContent for &'a mut MESSAGECONTENT {}

impl<'a, MESSAGEFILETYPE: TDMessageFileType> TDMessageFileType for &'a MESSAGEFILETYPE {}
impl<'a, MESSAGEFILETYPE: TDMessageFileType> TDMessageFileType for &'a mut MESSAGEFILETYPE {}

impl<'a, MESSAGEFORWARDORIGIN: TDMessageForwardOrigin> TDMessageForwardOrigin
    for &'a MESSAGEFORWARDORIGIN
{
}
impl<'a, MESSAGEFORWARDORIGIN: TDMessageForwardOrigin> TDMessageForwardOrigin
    for &'a mut MESSAGEFORWARDORIGIN
{
}

impl<'a, MESSAGESCHEDULINGSTATE: TDMessageSchedulingState> TDMessageSchedulingState
    for &'a MESSAGESCHEDULINGSTATE
{
}
impl<'a, MESSAGESCHEDULINGSTATE: TDMessageSchedulingState> TDMessageSchedulingState
    for &'a mut MESSAGESCHEDULINGSTATE
{
}

impl<'a, MESSAGESENDER: TDMessageSender> TDMessageSender for &'a MESSAGESENDER {}
impl<'a, MESSAGESENDER: TDMessageSender> TDMessageSender for &'a mut MESSAGESENDER {}

impl<'a, MESSAGESENDINGSTATE: TDMessageSendingState> TDMessageSendingState
    for &'a MESSAGESENDINGSTATE
{
}
impl<'a, MESSAGESENDINGSTATE: TDMessageSendingState> TDMessageSendingState
    for &'a mut MESSAGESENDINGSTATE
{
}

impl<'a, NETWORKSTATISTICSENTRY: TDNetworkStatisticsEntry> TDNetworkStatisticsEntry
    for &'a NETWORKSTATISTICSENTRY
{
}
impl<'a, NETWORKSTATISTICSENTRY: TDNetworkStatisticsEntry> TDNetworkStatisticsEntry
    for &'a mut NETWORKSTATISTICSENTRY
{
}

impl<'a, NETWORKTYPE: TDNetworkType> TDNetworkType for &'a NETWORKTYPE {}
impl<'a, NETWORKTYPE: TDNetworkType> TDNetworkType for &'a mut NETWORKTYPE {}

impl<'a, NOTIFICATIONGROUPTYPE: TDNotificationGroupType> TDNotificationGroupType
    for &'a NOTIFICATIONGROUPTYPE
{
}
impl<'a, NOTIFICATIONGROUPTYPE: TDNotificationGroupType> TDNotificationGroupType
    for &'a mut NOTIFICATIONGROUPTYPE
{
}

impl<'a, NOTIFICATIONSETTINGSSCOPE: TDNotificationSettingsScope> TDNotificationSettingsScope
    for &'a NOTIFICATIONSETTINGSSCOPE
{
}
impl<'a, NOTIFICATIONSETTINGSSCOPE: TDNotificationSettingsScope> TDNotificationSettingsScope
    for &'a mut NOTIFICATIONSETTINGSSCOPE
{
}

impl<'a, NOTIFICATIONTYPE: TDNotificationType> TDNotificationType for &'a NOTIFICATIONTYPE {}
impl<'a, NOTIFICATIONTYPE: TDNotificationType> TDNotificationType for &'a mut NOTIFICATIONTYPE {}

impl<'a, OPTIONVALUE: TDOptionValue> TDOptionValue for &'a OPTIONVALUE {}
impl<'a, OPTIONVALUE: TDOptionValue> TDOptionValue for &'a mut OPTIONVALUE {}

impl<'a, PAGEBLOCK: TDPageBlock> TDPageBlock for &'a PAGEBLOCK {}
impl<'a, PAGEBLOCK: TDPageBlock> TDPageBlock for &'a mut PAGEBLOCK {}

impl<'a, PAGEBLOCKHORIZONTALALIGNMENT: TDPageBlockHorizontalAlignment>
    TDPageBlockHorizontalAlignment for &'a PAGEBLOCKHORIZONTALALIGNMENT
{
}
impl<'a, PAGEBLOCKHORIZONTALALIGNMENT: TDPageBlockHorizontalAlignment>
    TDPageBlockHorizontalAlignment for &'a mut PAGEBLOCKHORIZONTALALIGNMENT
{
}

impl<'a, PAGEBLOCKVERTICALALIGNMENT: TDPageBlockVerticalAlignment> TDPageBlockVerticalAlignment
    for &'a PAGEBLOCKVERTICALALIGNMENT
{
}
impl<'a, PAGEBLOCKVERTICALALIGNMENT: TDPageBlockVerticalAlignment> TDPageBlockVerticalAlignment
    for &'a mut PAGEBLOCKVERTICALALIGNMENT
{
}

impl<'a, PASSPORTELEMENT: TDPassportElement> TDPassportElement for &'a PASSPORTELEMENT {}
impl<'a, PASSPORTELEMENT: TDPassportElement> TDPassportElement for &'a mut PASSPORTELEMENT {}

impl<'a, PASSPORTELEMENTERRORSOURCE: TDPassportElementErrorSource> TDPassportElementErrorSource
    for &'a PASSPORTELEMENTERRORSOURCE
{
}
impl<'a, PASSPORTELEMENTERRORSOURCE: TDPassportElementErrorSource> TDPassportElementErrorSource
    for &'a mut PASSPORTELEMENTERRORSOURCE
{
}

impl<'a, PASSPORTELEMENTTYPE: TDPassportElementType> TDPassportElementType
    for &'a PASSPORTELEMENTTYPE
{
}
impl<'a, PASSPORTELEMENTTYPE: TDPassportElementType> TDPassportElementType
    for &'a mut PASSPORTELEMENTTYPE
{
}

impl<'a, POLLTYPE: TDPollType> TDPollType for &'a POLLTYPE {}
impl<'a, POLLTYPE: TDPollType> TDPollType for &'a mut POLLTYPE {}

impl<'a, PROXYTYPE: TDProxyType> TDProxyType for &'a PROXYTYPE {}
impl<'a, PROXYTYPE: TDProxyType> TDProxyType for &'a mut PROXYTYPE {}

impl<'a, PUBLICCHATTYPE: TDPublicChatType> TDPublicChatType for &'a PUBLICCHATTYPE {}
impl<'a, PUBLICCHATTYPE: TDPublicChatType> TDPublicChatType for &'a mut PUBLICCHATTYPE {}

impl<'a, PUSHMESSAGECONTENT: TDPushMessageContent> TDPushMessageContent for &'a PUSHMESSAGECONTENT {}
impl<'a, PUSHMESSAGECONTENT: TDPushMessageContent> TDPushMessageContent
    for &'a mut PUSHMESSAGECONTENT
{
}

impl<'a, REPLYMARKUP: TDReplyMarkup> TDReplyMarkup for &'a REPLYMARKUP {}
impl<'a, REPLYMARKUP: TDReplyMarkup> TDReplyMarkup for &'a mut REPLYMARKUP {}

impl<'a, RESETPASSWORDRESULT: TDResetPasswordResult> TDResetPasswordResult
    for &'a RESETPASSWORDRESULT
{
}
impl<'a, RESETPASSWORDRESULT: TDResetPasswordResult> TDResetPasswordResult
    for &'a mut RESETPASSWORDRESULT
{
}

impl<'a, RICHTEXT: TDRichText> TDRichText for &'a RICHTEXT {}
impl<'a, RICHTEXT: TDRichText> TDRichText for &'a mut RICHTEXT {}

impl<'a, SEARCHMESSAGESFILTER: TDSearchMessagesFilter> TDSearchMessagesFilter
    for &'a SEARCHMESSAGESFILTER
{
}
impl<'a, SEARCHMESSAGESFILTER: TDSearchMessagesFilter> TDSearchMessagesFilter
    for &'a mut SEARCHMESSAGESFILTER
{
}

impl<'a, SECRETCHATSTATE: TDSecretChatState> TDSecretChatState for &'a SECRETCHATSTATE {}
impl<'a, SECRETCHATSTATE: TDSecretChatState> TDSecretChatState for &'a mut SECRETCHATSTATE {}

impl<'a, STATISTICALGRAPH: TDStatisticalGraph> TDStatisticalGraph for &'a STATISTICALGRAPH {}
impl<'a, STATISTICALGRAPH: TDStatisticalGraph> TDStatisticalGraph for &'a mut STATISTICALGRAPH {}

impl<'a, SUGGESTEDACTION: TDSuggestedAction> TDSuggestedAction for &'a SUGGESTEDACTION {}
impl<'a, SUGGESTEDACTION: TDSuggestedAction> TDSuggestedAction for &'a mut SUGGESTEDACTION {}

impl<'a, SUPERGROUPMEMBERSFILTER: TDSupergroupMembersFilter> TDSupergroupMembersFilter
    for &'a SUPERGROUPMEMBERSFILTER
{
}
impl<'a, SUPERGROUPMEMBERSFILTER: TDSupergroupMembersFilter> TDSupergroupMembersFilter
    for &'a mut SUPERGROUPMEMBERSFILTER
{
}

impl<'a, TMEURLTYPE: TDTMeUrlType> TDTMeUrlType for &'a TMEURLTYPE {}
impl<'a, TMEURLTYPE: TDTMeUrlType> TDTMeUrlType for &'a mut TMEURLTYPE {}

impl<'a, TEXTENTITYTYPE: TDTextEntityType> TDTextEntityType for &'a TEXTENTITYTYPE {}
impl<'a, TEXTENTITYTYPE: TDTextEntityType> TDTextEntityType for &'a mut TEXTENTITYTYPE {}

impl<'a, TEXTPARSEMODE: TDTextParseMode> TDTextParseMode for &'a TEXTPARSEMODE {}
impl<'a, TEXTPARSEMODE: TDTextParseMode> TDTextParseMode for &'a mut TEXTPARSEMODE {}

impl<'a, THUMBNAILFORMAT: TDThumbnailFormat> TDThumbnailFormat for &'a THUMBNAILFORMAT {}
impl<'a, THUMBNAILFORMAT: TDThumbnailFormat> TDThumbnailFormat for &'a mut THUMBNAILFORMAT {}

impl<'a, TOPCHATCATEGORY: TDTopChatCategory> TDTopChatCategory for &'a TOPCHATCATEGORY {}
impl<'a, TOPCHATCATEGORY: TDTopChatCategory> TDTopChatCategory for &'a mut TOPCHATCATEGORY {}

impl<'a, UPDATE: TDUpdate> TDUpdate for &'a UPDATE {}
impl<'a, UPDATE: TDUpdate> TDUpdate for &'a mut UPDATE {}

impl<'a, USERPRIVACYSETTING: TDUserPrivacySetting> TDUserPrivacySetting for &'a USERPRIVACYSETTING {}
impl<'a, USERPRIVACYSETTING: TDUserPrivacySetting> TDUserPrivacySetting
    for &'a mut USERPRIVACYSETTING
{
}

impl<'a, USERPRIVACYSETTINGRULE: TDUserPrivacySettingRule> TDUserPrivacySettingRule
    for &'a USERPRIVACYSETTINGRULE
{
}
impl<'a, USERPRIVACYSETTINGRULE: TDUserPrivacySettingRule> TDUserPrivacySettingRule
    for &'a mut USERPRIVACYSETTINGRULE
{
}

impl<'a, USERSTATUS: TDUserStatus> TDUserStatus for &'a USERSTATUS {}
impl<'a, USERSTATUS: TDUserStatus> TDUserStatus for &'a mut USERSTATUS {}

impl<'a, USERTYPE: TDUserType> TDUserType for &'a USERTYPE {}
impl<'a, USERTYPE: TDUserType> TDUserType for &'a mut USERTYPE {}

impl<'a, VECTORPATHCOMMAND: TDVectorPathCommand> TDVectorPathCommand for &'a VECTORPATHCOMMAND {}
impl<'a, VECTORPATHCOMMAND: TDVectorPathCommand> TDVectorPathCommand for &'a mut VECTORPATHCOMMAND {}

pub(super) fn number_from_string<'de, T, D>(deserializer: D) -> Result<T, D::Error>
where
    T: FromStr,
    T::Err: Display,
    D: Deserializer<'de>,
{
    let s = String::deserialize(deserializer)?;
    T::from_str(&s).map_err(SerdeDeError::custom)
}

pub(super) fn string_to_number<T, S>(value: &T, serializer: S) -> Result<S::Ok, S::Error>
where
    T: Display,
    S: Serializer,
{
    serializer.collect_str(value)
}

pub(super) fn vec_of_i64_from_str<'de, D>(deserializer: D) -> Result<Vec<i64>, D::Error>
where
    D: Deserializer<'de>,
{
    let s = Vec::<String>::deserialize(deserializer)?;
    let mut r = Vec::new();
    for v in s {
        match v.parse::<i64>() {
            Ok(v) => r.push(v),
            Err(e) => return Err(D::Error::custom(format!("can't deserialize to i64: {}", e))),
        }
    }
    Ok(r)
}

#[cfg(test)]
mod tests {
    use crate::types::{
        ClosedVectorPath, File, Message, MessageContent, Sticker, Thumbnail, Update,
    };
    use serde::de::DeserializeOwned;

    #[test]
    fn test_deserialize_closed_vector_path() {
        assert(
            r#"[{"@type":"closedVectorPath","commands":[{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":196.250000,"y":296.250000},"end_control_point":{"@type":"point","x":175.625000,"y":296.875000},"end_point":{"@type":"point","x":153.750000,"y":295.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":141.250000,"y":294.375000},"end_control_point":{"@type":"point","x":128.125000,"y":291.250000},"end_point":{"@type":"point","x":117.500000,"y":285.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":113.750000,"y":283.750000},"end_control_point":{"@type":"point","x":109.375000,"y":279.375000},"end_point":{"@type":"point","x":105.625000,"y":278.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":96.250000,"y":276.250000},"end_control_point":{"@type":"point","x":84.375000,"y":284.375000},"end_point":{"@type":"point","x":75.000000,"y":283.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":51.875000,"y":280.000000},"end_control_point":{"@type":"point","x":43.125000,"y":251.250000},"end_point":{"@type":"point","x":40.625000,"y":231.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":38.125000,"y":211.250000},"end_control_point":{"@type":"point","x":41.250000,"y":178.125000},"end_point":{"@type":"point","x":59.375000,"y":163.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":69.375000,"y":156.250000},"end_control_point":{"@type":"point","x":84.375000,"y":163.125000},"end_point":{"@type":"point","x":96.250000,"y":156.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":105.000000,"y":150.625000},"end_control_point":{"@type":"point","x":108.750000,"y":138.125000},"end_point":{"@type":"point","x":115.625000,"y":130.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":125.625000,"y":119.375000},"end_control_point":{"@type":"point","x":138.125000,"y":110.625000},"end_point":{"@type":"point","x":147.500000,"y":98.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":160.625000,"y":82.500000},"end_control_point":{"@type":"point","x":135.625000,"y":38.125000},"end_point":{"@type":"point","x":168.750000,"y":38.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":173.750000,"y":38.125000},"end_control_point":{"@type":"point","x":178.750000,"y":40.000000},"end_point":{"@type":"point","x":183.125000,"y":43.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":221.875000,"y":73.125000},"end_control_point":{"@type":"point","x":183.750000,"y":112.500000},"end_point":{"@type":"point","x":188.125000,"y":136.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":189.375000,"y":143.750000},"end_control_point":{"@type":"point","x":203.125000,"y":143.125000},"end_point":{"@type":"point","x":208.125000,"y":143.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":230.625000,"y":141.875000},"end_control_point":{"@type":"point","x":271.250000,"y":141.250000},"end_point":{"@type":"point","x":280.000000,"y":168.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":284.375000,"y":181.875000},"end_control_point":{"@type":"point","x":277.500000,"y":186.875000},"end_point":{"@type":"point","x":277.500000,"y":196.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":277.500000,"y":198.750000},"end_control_point":{"@type":"point","x":287.500000,"y":209.375000},"end_point":{"@type":"point","x":284.375000,"y":221.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":283.125000,"y":225.000000},"end_control_point":{"@type":"point","x":281.250000,"y":228.125000},"end_point":{"@type":"point","x":279.375000,"y":231.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":279.375000,"y":231.250000},"end_control_point":{"@type":"point","x":273.125000,"y":235.625000},"end_point":{"@type":"point","x":273.125000,"y":236.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":276.250000,"y":246.875000},"end_control_point":{"@type":"point","x":276.875000,"y":257.500000},"end_point":{"@type":"point","x":267.500000,"y":265.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":265.625000,"y":267.500000},"end_control_point":{"@type":"point","x":262.500000,"y":267.500000},"end_point":{"@type":"point","x":261.250000,"y":270.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":260.625000,"y":273.125000},"end_control_point":{"@type":"point","x":261.875000,"y":277.500000},"end_point":{"@type":"point","x":260.000000,"y":280.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":255.000000,"y":298.125000},"end_control_point":{"@type":"point","x":233.750000,"y":301.875000},"end_point":{"@type":"point","x":218.125000,"y":301.875000}}]}]"#,
            |res: &serde_json::Result<Vec<ClosedVectorPath>>| res.is_ok(),
        )
    }

    #[test]
    fn test_deserialize_thumbnail() {
        assert(
            r#"{"@type":"thumbnail","format":{"@type":"thumbnailFormatWebp"},"width":101,"height":128,"file":{"@type":"file","id":573,"size":2672,"expected_size":2672,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"AAMCAQADFQABYr34JQdBM97Uqr0NPPmL7BZvomIAAs0BAAJS-jFFL2KLTiLKoDwBAAdtAAMjBA","unique_id":"AQADzQEAAlL6MUVy","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":2672}}}"#,
            |res: &serde_json::Result<Thumbnail>| res.is_ok(),
        )
    }

    #[test]
    fn test_deserialize_file() {
        assert(
            r#"{"@type":"file","id":572,"size":18100,"expected_size":18100,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"CAACAgEAAxUAAWK9-CUHQTPe1Kq9DTz5i-wWb6JiAALNAQACUvoxRS9ii04iyqA8IwQ","unique_id":"AgADzQEAAlL6MUU","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":18100}}"#,
            |res: &serde_json::Result<File>| res.is_ok(),
        )
    }

    #[test]
    fn test_deserialize_sticker() {
        assert(
            r#"{"@type":"sticker","set_id":"1258816259751983","width":300,"height":380,"emoji":"\ud83d\udc4d","is_animated":true,"is_mask":false,"outline":[{"@type":"closedVectorPath","commands":[{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":196.250000,"y":296.250000},"end_control_point":{"@type":"point","x":175.625000,"y":296.875000},"end_point":{"@type":"point","x":153.750000,"y":295.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":141.250000,"y":294.375000},"end_control_point":{"@type":"point","x":128.125000,"y":291.250000},"end_point":{"@type":"point","x":117.500000,"y":285.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":113.750000,"y":283.750000},"end_control_point":{"@type":"point","x":109.375000,"y":279.375000},"end_point":{"@type":"point","x":105.625000,"y":278.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":96.250000,"y":276.250000},"end_control_point":{"@type":"point","x":84.375000,"y":284.375000},"end_point":{"@type":"point","x":75.000000,"y":283.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":51.875000,"y":280.000000},"end_control_point":{"@type":"point","x":43.125000,"y":251.250000},"end_point":{"@type":"point","x":40.625000,"y":231.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":38.125000,"y":211.250000},"end_control_point":{"@type":"point","x":41.250000,"y":178.125000},"end_point":{"@type":"point","x":59.375000,"y":163.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":69.375000,"y":156.250000},"end_control_point":{"@type":"point","x":84.375000,"y":163.125000},"end_point":{"@type":"point","x":96.250000,"y":156.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":105.000000,"y":150.625000},"end_control_point":{"@type":"point","x":108.750000,"y":138.125000},"end_point":{"@type":"point","x":115.625000,"y":130.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":125.625000,"y":119.375000},"end_control_point":{"@type":"point","x":138.125000,"y":110.625000},"end_point":{"@type":"point","x":147.500000,"y":98.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":160.625000,"y":82.500000},"end_control_point":{"@type":"point","x":135.625000,"y":38.125000},"end_point":{"@type":"point","x":168.750000,"y":38.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":173.750000,"y":38.125000},"end_control_point":{"@type":"point","x":178.750000,"y":40.000000},"end_point":{"@type":"point","x":183.125000,"y":43.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":221.875000,"y":73.125000},"end_control_point":{"@type":"point","x":183.750000,"y":112.500000},"end_point":{"@type":"point","x":188.125000,"y":136.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":189.375000,"y":143.750000},"end_control_point":{"@type":"point","x":203.125000,"y":143.125000},"end_point":{"@type":"point","x":208.125000,"y":143.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":230.625000,"y":141.875000},"end_control_point":{"@type":"point","x":271.250000,"y":141.250000},"end_point":{"@type":"point","x":280.000000,"y":168.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":284.375000,"y":181.875000},"end_control_point":{"@type":"point","x":277.500000,"y":186.875000},"end_point":{"@type":"point","x":277.500000,"y":196.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":277.500000,"y":198.750000},"end_control_point":{"@type":"point","x":287.500000,"y":209.375000},"end_point":{"@type":"point","x":284.375000,"y":221.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":283.125000,"y":225.000000},"end_control_point":{"@type":"point","x":281.250000,"y":228.125000},"end_point":{"@type":"point","x":279.375000,"y":231.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":279.375000,"y":231.250000},"end_control_point":{"@type":"point","x":273.125000,"y":235.625000},"end_point":{"@type":"point","x":273.125000,"y":236.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":276.250000,"y":246.875000},"end_control_point":{"@type":"point","x":276.875000,"y":257.500000},"end_point":{"@type":"point","x":267.500000,"y":265.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":265.625000,"y":267.500000},"end_control_point":{"@type":"point","x":262.500000,"y":267.500000},"end_point":{"@type":"point","x":261.250000,"y":270.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":260.625000,"y":273.125000},"end_control_point":{"@type":"point","x":261.875000,"y":277.500000},"end_point":{"@type":"point","x":260.000000,"y":280.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":255.000000,"y":298.125000},"end_control_point":{"@type":"point","x":233.750000,"y":301.875000},"end_point":{"@type":"point","x":218.125000,"y":301.875000}}]}],"thumbnail":{"@type":"thumbnail","format":{"@type":"thumbnailFormatWebp"},"width":101,"height":128,"file":{"@type":"file","id":573,"size":2672,"expected_size":2672,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"AAMCAQADFQABYr34JQdBM97Uqr0NPPmL7BZvomIAAs0BAAJS-jFFL2KLTiLKoDwBAAdtAAMjBA","unique_id":"AQADzQEAAlL6MUVy","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":2672}}},"sticker":{"@type":"file","id":572,"size":18100,"expected_size":18100,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"CAACAgEAAxUAAWK9-CUHQTPe1Kq9DTz5i-wWb6JiAALNAQACUvoxRS9ii04iyqA8IwQ","unique_id":"AgADzQEAAlL6MUU","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":18100}}}"#,
            |res: &serde_json::Result<Sticker>| res.is_ok(),
        )
    }

    #[test]
    fn test_deserialize_message_animated_emoji() {
        assert(
            r#"{"@type":"messageAnimatedEmoji","animated_emoji":{"@type":"animatedEmoji","sticker":{"@type":"sticker","set_id":"1258816259751983","width":300,"height":380,"emoji":"\ud83d\udc4d","is_animated":true,"is_mask":false,"outline":[{"@type":"closedVectorPath","commands":[{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":196.250000,"y":296.250000},"end_control_point":{"@type":"point","x":175.625000,"y":296.875000},"end_point":{"@type":"point","x":153.750000,"y":295.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":141.250000,"y":294.375000},"end_control_point":{"@type":"point","x":128.125000,"y":291.250000},"end_point":{"@type":"point","x":117.500000,"y":285.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":113.750000,"y":283.750000},"end_control_point":{"@type":"point","x":109.375000,"y":279.375000},"end_point":{"@type":"point","x":105.625000,"y":278.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":96.250000,"y":276.250000},"end_control_point":{"@type":"point","x":84.375000,"y":284.375000},"end_point":{"@type":"point","x":75.000000,"y":283.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":51.875000,"y":280.000000},"end_control_point":{"@type":"point","x":43.125000,"y":251.250000},"end_point":{"@type":"point","x":40.625000,"y":231.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":38.125000,"y":211.250000},"end_control_point":{"@type":"point","x":41.250000,"y":178.125000},"end_point":{"@type":"point","x":59.375000,"y":163.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":69.375000,"y":156.250000},"end_control_point":{"@type":"point","x":84.375000,"y":163.125000},"end_point":{"@type":"point","x":96.250000,"y":156.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":105.000000,"y":150.625000},"end_control_point":{"@type":"point","x":108.750000,"y":138.125000},"end_point":{"@type":"point","x":115.625000,"y":130.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":125.625000,"y":119.375000},"end_control_point":{"@type":"point","x":138.125000,"y":110.625000},"end_point":{"@type":"point","x":147.500000,"y":98.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":160.625000,"y":82.500000},"end_control_point":{"@type":"point","x":135.625000,"y":38.125000},"end_point":{"@type":"point","x":168.750000,"y":38.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":173.750000,"y":38.125000},"end_control_point":{"@type":"point","x":178.750000,"y":40.000000},"end_point":{"@type":"point","x":183.125000,"y":43.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":221.875000,"y":73.125000},"end_control_point":{"@type":"point","x":183.750000,"y":112.500000},"end_point":{"@type":"point","x":188.125000,"y":136.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":189.375000,"y":143.750000},"end_control_point":{"@type":"point","x":203.125000,"y":143.125000},"end_point":{"@type":"point","x":208.125000,"y":143.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":230.625000,"y":141.875000},"end_control_point":{"@type":"point","x":271.250000,"y":141.250000},"end_point":{"@type":"point","x":280.000000,"y":168.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":284.375000,"y":181.875000},"end_control_point":{"@type":"point","x":277.500000,"y":186.875000},"end_point":{"@type":"point","x":277.500000,"y":196.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":277.500000,"y":198.750000},"end_control_point":{"@type":"point","x":287.500000,"y":209.375000},"end_point":{"@type":"point","x":284.375000,"y":221.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":283.125000,"y":225.000000},"end_control_point":{"@type":"point","x":281.250000,"y":228.125000},"end_point":{"@type":"point","x":279.375000,"y":231.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":279.375000,"y":231.250000},"end_control_point":{"@type":"point","x":273.125000,"y":235.625000},"end_point":{"@type":"point","x":273.125000,"y":236.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":276.250000,"y":246.875000},"end_control_point":{"@type":"point","x":276.875000,"y":257.500000},"end_point":{"@type":"point","x":267.500000,"y":265.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":265.625000,"y":267.500000},"end_control_point":{"@type":"point","x":262.500000,"y":267.500000},"end_point":{"@type":"point","x":261.250000,"y":270.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":260.625000,"y":273.125000},"end_control_point":{"@type":"point","x":261.875000,"y":277.500000},"end_point":{"@type":"point","x":260.000000,"y":280.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":255.000000,"y":298.125000},"end_control_point":{"@type":"point","x":233.750000,"y":301.875000},"end_point":{"@type":"point","x":218.125000,"y":301.875000}}]}],"thumbnail":{"@type":"thumbnail","format":{"@type":"thumbnailFormatWebp"},"width":101,"height":128,"file":{"@type":"file","id":573,"size":2672,"expected_size":2672,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"AAMCAQADFQABYr34JQdBM97Uqr0NPPmL7BZvomIAAs0BAAJS-jFFL2KLTiLKoDwBAAdtAAMjBA","unique_id":"AQADzQEAAlL6MUVy","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":2672}}},"sticker":{"@type":"file","id":572,"size":18100,"expected_size":18100,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"CAACAgEAAxUAAWK9-CUHQTPe1Kq9DTz5i-wWb6JiAALNAQACUvoxRS9ii04iyqA8IwQ","unique_id":"AgADzQEAAlL6MUU","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":18100}}},"fitzpatrick_type":0},"emoji":"\ud83d\udc4d"}"#,
            |res: &serde_json::Result<MessageContent>| {
                matches!(res, Ok(MessageContent::MessageAnimatedEmoji(_)))
            },
        )
    }

    #[test]
    fn test_deserialize_message() {
        assert(
            r#"{"@type":"message","id":179306496,"sender_id":{"@type":"messageSenderUser","user_id":5049844889},"chat_id":5129286886,"is_outgoing":true,"is_pinned":false,"can_be_edited":false,"can_be_forwarded":true,"can_be_saved":true,"can_be_deleted_only_for_self":true,"can_be_deleted_for_all_users":true,"can_get_statistics":false,"can_get_message_thread":false,"can_get_viewers":false,"can_get_media_timestamp_links":false,"has_timestamped_media":true,"is_channel_post":false,"contains_unread_mention":false,"date":1648402824,"edit_date":0,"reply_in_chat_id":0,"reply_to_message_id":0,"message_thread_id":0,"ttl":0,"ttl_expires_in":0.000000,"via_bot_user_id":0,"author_signature":"","media_album_id":"0","restriction_reason":"","content":{"@type":"messageAnimatedEmoji","animated_emoji":{"@type":"animatedEmoji","sticker":{"@type":"sticker","set_id":"1258816259751983","width":300,"height":380,"emoji":"\ud83d\udc4d","is_animated":true,"is_mask":false,"outline":[{"@type":"closedVectorPath","commands":[{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":196.250000,"y":296.250000},"end_control_point":{"@type":"point","x":175.625000,"y":296.875000},"end_point":{"@type":"point","x":153.750000,"y":295.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":141.250000,"y":294.375000},"end_control_point":{"@type":"point","x":128.125000,"y":291.250000},"end_point":{"@type":"point","x":117.500000,"y":285.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":113.750000,"y":283.750000},"end_control_point":{"@type":"point","x":109.375000,"y":279.375000},"end_point":{"@type":"point","x":105.625000,"y":278.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":96.250000,"y":276.250000},"end_control_point":{"@type":"point","x":84.375000,"y":284.375000},"end_point":{"@type":"point","x":75.000000,"y":283.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":51.875000,"y":280.000000},"end_control_point":{"@type":"point","x":43.125000,"y":251.250000},"end_point":{"@type":"point","x":40.625000,"y":231.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":38.125000,"y":211.250000},"end_control_point":{"@type":"point","x":41.250000,"y":178.125000},"end_point":{"@type":"point","x":59.375000,"y":163.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":69.375000,"y":156.250000},"end_control_point":{"@type":"point","x":84.375000,"y":163.125000},"end_point":{"@type":"point","x":96.250000,"y":156.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":105.000000,"y":150.625000},"end_control_point":{"@type":"point","x":108.750000,"y":138.125000},"end_point":{"@type":"point","x":115.625000,"y":130.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":125.625000,"y":119.375000},"end_control_point":{"@type":"point","x":138.125000,"y":110.625000},"end_point":{"@type":"point","x":147.500000,"y":98.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":160.625000,"y":82.500000},"end_control_point":{"@type":"point","x":135.625000,"y":38.125000},"end_point":{"@type":"point","x":168.750000,"y":38.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":173.750000,"y":38.125000},"end_control_point":{"@type":"point","x":178.750000,"y":40.000000},"end_point":{"@type":"point","x":183.125000,"y":43.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":221.875000,"y":73.125000},"end_control_point":{"@type":"point","x":183.750000,"y":112.500000},"end_point":{"@type":"point","x":188.125000,"y":136.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":189.375000,"y":143.750000},"end_control_point":{"@type":"point","x":203.125000,"y":143.125000},"end_point":{"@type":"point","x":208.125000,"y":143.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":230.625000,"y":141.875000},"end_control_point":{"@type":"point","x":271.250000,"y":141.250000},"end_point":{"@type":"point","x":280.000000,"y":168.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":284.375000,"y":181.875000},"end_control_point":{"@type":"point","x":277.500000,"y":186.875000},"end_point":{"@type":"point","x":277.500000,"y":196.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":277.500000,"y":198.750000},"end_control_point":{"@type":"point","x":287.500000,"y":209.375000},"end_point":{"@type":"point","x":284.375000,"y":221.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":283.125000,"y":225.000000},"end_control_point":{"@type":"point","x":281.250000,"y":228.125000},"end_point":{"@type":"point","x":279.375000,"y":231.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":279.375000,"y":231.250000},"end_control_point":{"@type":"point","x":273.125000,"y":235.625000},"end_point":{"@type":"point","x":273.125000,"y":236.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":276.250000,"y":246.875000},"end_control_point":{"@type":"point","x":276.875000,"y":257.500000},"end_point":{"@type":"point","x":267.500000,"y":265.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":265.625000,"y":267.500000},"end_control_point":{"@type":"point","x":262.500000,"y":267.500000},"end_point":{"@type":"point","x":261.250000,"y":270.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":260.625000,"y":273.125000},"end_control_point":{"@type":"point","x":261.875000,"y":277.500000},"end_point":{"@type":"point","x":260.000000,"y":280.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":255.000000,"y":298.125000},"end_control_point":{"@type":"point","x":233.750000,"y":301.875000},"end_point":{"@type":"point","x":218.125000,"y":301.875000}}]}],"thumbnail":{"@type":"thumbnail","format":{"@type":"thumbnailFormatWebp"},"width":101,"height":128,"file":{"@type":"file","id":573,"size":2672,"expected_size":2672,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"AAMCAQADFQABYr34JQdBM97Uqr0NPPmL7BZvomIAAs0BAAJS-jFFL2KLTiLKoDwBAAdtAAMjBA","unique_id":"AQADzQEAAlL6MUVy","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":2672}}},"sticker":{"@type":"file","id":572,"size":18100,"expected_size":18100,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"CAACAgEAAxUAAWK9-CUHQTPe1Kq9DTz5i-wWb6JiAALNAQACUvoxRS9ii04iyqA8IwQ","unique_id":"AgADzQEAAlL6MUU","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":18100}}},"fitzpatrick_type":0},"emoji":"\ud83d\udc4d"}}"#,
            |res: &serde_json::Result<Message>| res.is_ok(),
        )
    }

    #[test]
    fn test_deserialize_update_chat_last_message() {
        assert(
            r#"{"@type":"updateChatLastMessage","chat_id":5129286886,"last_message":{"@type":"message","id":179306496,"sender_id":{"@type":"messageSenderUser","user_id":5049844889},"chat_id":5129286886,"is_outgoing":true,"is_pinned":false,"can_be_edited":false,"can_be_forwarded":true,"can_be_saved":true,"can_be_deleted_only_for_self":true,"can_be_deleted_for_all_users":true,"can_get_statistics":false,"can_get_message_thread":false,"can_get_viewers":false,"can_get_media_timestamp_links":false,"has_timestamped_media":true,"is_channel_post":false,"contains_unread_mention":false,"date":1648402824,"edit_date":0,"reply_in_chat_id":0,"reply_to_message_id":0,"message_thread_id":0,"ttl":0,"ttl_expires_in":0.000000,"via_bot_user_id":0,"author_signature":"","media_album_id":"0","restriction_reason":"","content":{"@type":"messageAnimatedEmoji","animated_emoji":{"@type":"animatedEmoji","sticker":{"@type":"sticker","set_id":"1258816259751983","width":300,"height":380,"emoji":"\ud83d\udc4d","is_animated":true,"is_mask":false,"outline":[{"@type":"closedVectorPath","commands":[{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":196.250000,"y":296.250000},"end_control_point":{"@type":"point","x":175.625000,"y":296.875000},"end_point":{"@type":"point","x":153.750000,"y":295.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":141.250000,"y":294.375000},"end_control_point":{"@type":"point","x":128.125000,"y":291.250000},"end_point":{"@type":"point","x":117.500000,"y":285.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":113.750000,"y":283.750000},"end_control_point":{"@type":"point","x":109.375000,"y":279.375000},"end_point":{"@type":"point","x":105.625000,"y":278.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":96.250000,"y":276.250000},"end_control_point":{"@type":"point","x":84.375000,"y":284.375000},"end_point":{"@type":"point","x":75.000000,"y":283.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":51.875000,"y":280.000000},"end_control_point":{"@type":"point","x":43.125000,"y":251.250000},"end_point":{"@type":"point","x":40.625000,"y":231.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":38.125000,"y":211.250000},"end_control_point":{"@type":"point","x":41.250000,"y":178.125000},"end_point":{"@type":"point","x":59.375000,"y":163.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":69.375000,"y":156.250000},"end_control_point":{"@type":"point","x":84.375000,"y":163.125000},"end_point":{"@type":"point","x":96.250000,"y":156.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":105.000000,"y":150.625000},"end_control_point":{"@type":"point","x":108.750000,"y":138.125000},"end_point":{"@type":"point","x":115.625000,"y":130.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":125.625000,"y":119.375000},"end_control_point":{"@type":"point","x":138.125000,"y":110.625000},"end_point":{"@type":"point","x":147.500000,"y":98.750000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":160.625000,"y":82.500000},"end_control_point":{"@type":"point","x":135.625000,"y":38.125000},"end_point":{"@type":"point","x":168.750000,"y":38.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":173.750000,"y":38.125000},"end_control_point":{"@type":"point","x":178.750000,"y":40.000000},"end_point":{"@type":"point","x":183.125000,"y":43.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":221.875000,"y":73.125000},"end_control_point":{"@type":"point","x":183.750000,"y":112.500000},"end_point":{"@type":"point","x":188.125000,"y":136.875000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":189.375000,"y":143.750000},"end_control_point":{"@type":"point","x":203.125000,"y":143.125000},"end_point":{"@type":"point","x":208.125000,"y":143.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":230.625000,"y":141.875000},"end_control_point":{"@type":"point","x":271.250000,"y":141.250000},"end_point":{"@type":"point","x":280.000000,"y":168.125000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":284.375000,"y":181.875000},"end_control_point":{"@type":"point","x":277.500000,"y":186.875000},"end_point":{"@type":"point","x":277.500000,"y":196.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":277.500000,"y":198.750000},"end_control_point":{"@type":"point","x":287.500000,"y":209.375000},"end_point":{"@type":"point","x":284.375000,"y":221.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":283.125000,"y":225.000000},"end_control_point":{"@type":"point","x":281.250000,"y":228.125000},"end_point":{"@type":"point","x":279.375000,"y":231.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":279.375000,"y":231.250000},"end_control_point":{"@type":"point","x":273.125000,"y":235.625000},"end_point":{"@type":"point","x":273.125000,"y":236.250000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":276.250000,"y":246.875000},"end_control_point":{"@type":"point","x":276.875000,"y":257.500000},"end_point":{"@type":"point","x":267.500000,"y":265.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":265.625000,"y":267.500000},"end_control_point":{"@type":"point","x":262.500000,"y":267.500000},"end_point":{"@type":"point","x":261.250000,"y":270.000000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":260.625000,"y":273.125000},"end_control_point":{"@type":"point","x":261.875000,"y":277.500000},"end_point":{"@type":"point","x":260.000000,"y":280.625000}},{"@type":"vectorPathCommandCubicBezierCurve","start_control_point":{"@type":"point","x":255.000000,"y":298.125000},"end_control_point":{"@type":"point","x":233.750000,"y":301.875000},"end_point":{"@type":"point","x":218.125000,"y":301.875000}}]}],"thumbnail":{"@type":"thumbnail","format":{"@type":"thumbnailFormatWebp"},"width":101,"height":128,"file":{"@type":"file","id":573,"size":2672,"expected_size":2672,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"AAMCAQADFQABYr34JQdBM97Uqr0NPPmL7BZvomIAAs0BAAJS-jFFL2KLTiLKoDwBAAdtAAMjBA","unique_id":"AQADzQEAAlL6MUVy","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":2672}}},"sticker":{"@type":"file","id":572,"size":18100,"expected_size":18100,"local":{"@type":"localFile","path":"","can_be_downloaded":true,"can_be_deleted":false,"is_downloading_active":false,"is_downloading_completed":false,"download_offset":0,"downloaded_prefix_size":0,"downloaded_size":0},"remote":{"@type":"remoteFile","id":"CAACAgEAAxUAAWK9-CUHQTPe1Kq9DTz5i-wWb6JiAALNAQACUvoxRS9ii04iyqA8IwQ","unique_id":"AgADzQEAAlL6MUU","is_uploading_active":false,"is_uploading_completed":true,"uploaded_size":18100}}},"fitzpatrick_type":0},"emoji":"\ud83d\udc4d"}},"positions":[],"@client_id":1}"#,
            |res: &serde_json::Result<Update>| matches!(res, Ok(Update::ChatLastMessage(_))),
        )
    }

    #[test]
    fn test_deserialize_update_auth_state_wait_tdlib_params() {
        assert(
            r#"{"@type":"updateAuthorizationState","authorization_state":{"@type":"authorizationStateWaitTdlibParameters"}}"#,
            |res: &serde_json::Result<Update>| matches!(res, Ok(Update::AuthorizationState(_))),
        )
    }

    fn assert<T: std::fmt::Debug + DeserializeOwned>(
        data: &'_ str,
        exp: fn(&serde_json::Result<T>) -> bool,
    ) {
        let result = serde_json::from_str(data);
        if !exp(&result) {
            panic!("does not match, got: {:?}", result);
        }
    }
}