rust_tdlib/types/
sticker_set.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Represents a sticker set
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct StickerSet {
8    #[doc(hidden)]
9    #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10    extra: Option<String>,
11    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12    client_id: Option<i32>,
13    /// Identifier of the sticker set
14
15    #[serde(
16        deserialize_with = "super::_common::number_from_string",
17        serialize_with = "super::_common::string_to_number"
18    )]
19    #[serde(default)]
20    id: i64,
21    /// Title of the sticker set
22
23    #[serde(default)]
24    title: String,
25    /// Name of the sticker set
26
27    #[serde(default)]
28    name: String,
29    /// Sticker set thumbnail in WEBP or TGS format with width and height 100; may be null. The file can be downloaded only before the thumbnail is changed
30    thumbnail: Option<Thumbnail>,
31    /// Sticker set thumbnail's outline represented as a list of closed vector paths; may be empty. The coordinate system origin is in the upper-left corner
32
33    #[serde(default)]
34    thumbnail_outline: Vec<ClosedVectorPath>,
35    /// True, if the sticker set has been installed by the current user
36
37    #[serde(default)]
38    is_installed: bool,
39    /// True, if the sticker set has been archived. A sticker set can't be installed and archived simultaneously
40
41    #[serde(default)]
42    is_archived: bool,
43    /// True, if the sticker set is official
44
45    #[serde(default)]
46    is_official: bool,
47    /// True, is the stickers in the set are animated
48
49    #[serde(default)]
50    is_animated: bool,
51    /// True, if the stickers in the set are masks
52
53    #[serde(default)]
54    is_masks: bool,
55    /// True for already viewed trending sticker sets
56
57    #[serde(default)]
58    is_viewed: bool,
59    /// List of stickers in this set
60
61    #[serde(default)]
62    stickers: Vec<Sticker>,
63    /// A list of emoji corresponding to the stickers in the same order. The list is only for informational purposes, because a sticker is always sent with a fixed emoji from the corresponding Sticker object
64
65    #[serde(default)]
66    emojis: Vec<Emojis>,
67}
68
69impl RObject for StickerSet {
70    #[doc(hidden)]
71    fn extra(&self) -> Option<&str> {
72        self.extra.as_deref()
73    }
74    #[doc(hidden)]
75    fn client_id(&self) -> Option<i32> {
76        self.client_id
77    }
78}
79
80impl StickerSet {
81    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
82        Ok(serde_json::from_str(json.as_ref())?)
83    }
84    pub fn builder() -> StickerSetBuilder {
85        let mut inner = StickerSet::default();
86        inner.extra = Some(Uuid::new_v4().to_string());
87
88        StickerSetBuilder { inner }
89    }
90
91    pub fn id(&self) -> i64 {
92        self.id
93    }
94
95    pub fn title(&self) -> &String {
96        &self.title
97    }
98
99    pub fn name(&self) -> &String {
100        &self.name
101    }
102
103    pub fn thumbnail(&self) -> &Option<Thumbnail> {
104        &self.thumbnail
105    }
106
107    pub fn thumbnail_outline(&self) -> &Vec<ClosedVectorPath> {
108        &self.thumbnail_outline
109    }
110
111    pub fn is_installed(&self) -> bool {
112        self.is_installed
113    }
114
115    pub fn is_archived(&self) -> bool {
116        self.is_archived
117    }
118
119    pub fn is_official(&self) -> bool {
120        self.is_official
121    }
122
123    pub fn is_animated(&self) -> bool {
124        self.is_animated
125    }
126
127    pub fn is_masks(&self) -> bool {
128        self.is_masks
129    }
130
131    pub fn is_viewed(&self) -> bool {
132        self.is_viewed
133    }
134
135    pub fn stickers(&self) -> &Vec<Sticker> {
136        &self.stickers
137    }
138
139    pub fn emojis(&self) -> &Vec<Emojis> {
140        &self.emojis
141    }
142}
143
144#[doc(hidden)]
145pub struct StickerSetBuilder {
146    inner: StickerSet,
147}
148
149#[deprecated]
150pub type RTDStickerSetBuilder = StickerSetBuilder;
151
152impl StickerSetBuilder {
153    pub fn build(&self) -> StickerSet {
154        self.inner.clone()
155    }
156
157    pub fn id(&mut self, id: i64) -> &mut Self {
158        self.inner.id = id;
159        self
160    }
161
162    pub fn title<T: AsRef<str>>(&mut self, title: T) -> &mut Self {
163        self.inner.title = title.as_ref().to_string();
164        self
165    }
166
167    pub fn name<T: AsRef<str>>(&mut self, name: T) -> &mut Self {
168        self.inner.name = name.as_ref().to_string();
169        self
170    }
171
172    pub fn thumbnail<T: AsRef<Thumbnail>>(&mut self, thumbnail: T) -> &mut Self {
173        self.inner.thumbnail = Some(thumbnail.as_ref().clone());
174        self
175    }
176
177    pub fn thumbnail_outline(&mut self, thumbnail_outline: Vec<ClosedVectorPath>) -> &mut Self {
178        self.inner.thumbnail_outline = thumbnail_outline;
179        self
180    }
181
182    pub fn is_installed(&mut self, is_installed: bool) -> &mut Self {
183        self.inner.is_installed = is_installed;
184        self
185    }
186
187    pub fn is_archived(&mut self, is_archived: bool) -> &mut Self {
188        self.inner.is_archived = is_archived;
189        self
190    }
191
192    pub fn is_official(&mut self, is_official: bool) -> &mut Self {
193        self.inner.is_official = is_official;
194        self
195    }
196
197    pub fn is_animated(&mut self, is_animated: bool) -> &mut Self {
198        self.inner.is_animated = is_animated;
199        self
200    }
201
202    pub fn is_masks(&mut self, is_masks: bool) -> &mut Self {
203        self.inner.is_masks = is_masks;
204        self
205    }
206
207    pub fn is_viewed(&mut self, is_viewed: bool) -> &mut Self {
208        self.inner.is_viewed = is_viewed;
209        self
210    }
211
212    pub fn stickers(&mut self, stickers: Vec<Sticker>) -> &mut Self {
213        self.inner.stickers = stickers;
214        self
215    }
216
217    pub fn emojis(&mut self, emojis: Vec<Emojis>) -> &mut Self {
218        self.inner.emojis = emojis;
219        self
220    }
221}
222
223impl AsRef<StickerSet> for StickerSet {
224    fn as_ref(&self) -> &StickerSet {
225        self
226    }
227}
228
229impl AsRef<StickerSet> for StickerSetBuilder {
230    fn as_ref(&self) -> &StickerSet {
231        &self.inner
232    }
233}