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
use std::ops::Deref;
use serde::{Deserialize, Serialize};
use crate::types::{PhotoSize, Sticker, StickerFormat, StickerType};
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct StickerSet {
pub name: String,
pub title: String,
#[serde(flatten)]
pub kind: StickerType,
#[serde(flatten)]
pub format: StickerFormat,
pub stickers: Vec<Sticker>,
pub thumb: Option<PhotoSize>,
}
impl Deref for StickerSet {
type Target = StickerType;
fn deref(&self) -> &Self::Target {
&self.kind
}
}
impl StickerSet {
#[must_use]
pub fn is_raster(&self) -> bool {
self.format.is_raster()
}
#[must_use]
pub fn is_animated(&self) -> bool {
self.format.is_animated()
}
#[must_use]
pub fn is_video(&self) -> bool {
self.format.is_video()
}
}
#[cfg(test)]
mod tests {
use crate::types::StickerSet;
#[test]
fn smoke_serde() {
let json = r#"{
"name": "teloxide_test",
"title": "teloxide-test",
"is_animated": false,
"is_video": false,
"sticker_type": "regular",
"contains_masks": false,
"stickers": [
{
"width": 512,
"height": 512,
"emoji": "⚙️",
"set_name": "teloxide_test",
"is_animated": false,
"is_video": false,
"type": "regular",
"thumb": {
"file_id": "AAMCAQADFQABYzB4ATH0sqXx351gZ5GpY1Z3Tl8AAlgCAAJ1t4hFbxNCoAg1-akBAAdtAAMpBA",
"file_unique_id": "AQADWAIAAnW3iEVy",
"file_size": 7698,
"width": 320,
"height": 320
},
"file_id": "CAACAgEAAxUAAWMweAEx9LKl8d-dYGeRqWNWd05fAAJYAgACdbeIRW8TQqAINfmpKQQ",
"file_unique_id": "AgADWAIAAnW3iEU",
"file_size": 12266
},
{
"width": 512,
"height": 512,
"emoji": "⚙️",
"set_name": "teloxide_test",
"is_animated": false,
"is_video": false,
"type": "regular",
"thumb": {
"file_id": "AAMCAQADFQABYzB4AcABR8-MuvGagis9Pk6liSAAAs8DAAL2YYBFNbvduoN1p7oBAAdtAAMpBA",
"file_unique_id": "AQADzwMAAvZhgEVy",
"file_size": 7780,
"width": 320,
"height": 320
},
"file_id": "CAACAgEAAxUAAWMweAHAAUfPjLrxmoIrPT5OpYkgAALPAwAC9mGARTW73bqDdae6KQQ",
"file_unique_id": "AgADzwMAAvZhgEU",
"file_size": 12158
}
]
}"#;
let set: StickerSet = serde_json::from_str(json).unwrap();
assert!(set.is_raster());
assert!(set.is_regular());
assert!(set.thumb.is_none());
assert_eq!(set.stickers.len(), 2);
}
}