rust_tdlib/types/
sticker.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct Sticker {
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 #[serde(
16 deserialize_with = "super::_common::number_from_string",
17 serialize_with = "super::_common::string_to_number"
18 )]
19 #[serde(default)]
20 set_id: i64,
21 #[serde(default)]
24 width: i32,
25 #[serde(default)]
28 height: i32,
29 #[serde(default)]
32 emoji: String,
33 #[serde(default)]
36 is_animated: bool,
37 #[serde(default)]
40 is_mask: bool,
41 mask_position: Option<MaskPosition>,
43 #[serde(default)]
46 outline: Vec<ClosedVectorPath>,
47 thumbnail: Option<Thumbnail>,
49 sticker: File,
51}
52
53impl RObject for Sticker {
54 #[doc(hidden)]
55 fn extra(&self) -> Option<&str> {
56 self.extra.as_deref()
57 }
58 #[doc(hidden)]
59 fn client_id(&self) -> Option<i32> {
60 self.client_id
61 }
62}
63
64impl Sticker {
65 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
66 Ok(serde_json::from_str(json.as_ref())?)
67 }
68 pub fn builder() -> StickerBuilder {
69 let mut inner = Sticker::default();
70 inner.extra = Some(Uuid::new_v4().to_string());
71
72 StickerBuilder { inner }
73 }
74
75 pub fn set_id(&self) -> i64 {
76 self.set_id
77 }
78
79 pub fn width(&self) -> i32 {
80 self.width
81 }
82
83 pub fn height(&self) -> i32 {
84 self.height
85 }
86
87 pub fn emoji(&self) -> &String {
88 &self.emoji
89 }
90
91 pub fn is_animated(&self) -> bool {
92 self.is_animated
93 }
94
95 pub fn is_mask(&self) -> bool {
96 self.is_mask
97 }
98
99 pub fn mask_position(&self) -> &Option<MaskPosition> {
100 &self.mask_position
101 }
102
103 pub fn outline(&self) -> &Vec<ClosedVectorPath> {
104 &self.outline
105 }
106
107 pub fn thumbnail(&self) -> &Option<Thumbnail> {
108 &self.thumbnail
109 }
110
111 pub fn sticker(&self) -> &File {
112 &self.sticker
113 }
114}
115
116#[doc(hidden)]
117pub struct StickerBuilder {
118 inner: Sticker,
119}
120
121#[deprecated]
122pub type RTDStickerBuilder = StickerBuilder;
123
124impl StickerBuilder {
125 pub fn build(&self) -> Sticker {
126 self.inner.clone()
127 }
128
129 pub fn set_id(&mut self, set_id: i64) -> &mut Self {
130 self.inner.set_id = set_id;
131 self
132 }
133
134 pub fn width(&mut self, width: i32) -> &mut Self {
135 self.inner.width = width;
136 self
137 }
138
139 pub fn height(&mut self, height: i32) -> &mut Self {
140 self.inner.height = height;
141 self
142 }
143
144 pub fn emoji<T: AsRef<str>>(&mut self, emoji: T) -> &mut Self {
145 self.inner.emoji = emoji.as_ref().to_string();
146 self
147 }
148
149 pub fn is_animated(&mut self, is_animated: bool) -> &mut Self {
150 self.inner.is_animated = is_animated;
151 self
152 }
153
154 pub fn is_mask(&mut self, is_mask: bool) -> &mut Self {
155 self.inner.is_mask = is_mask;
156 self
157 }
158
159 pub fn mask_position<T: AsRef<MaskPosition>>(&mut self, mask_position: T) -> &mut Self {
160 self.inner.mask_position = Some(mask_position.as_ref().clone());
161 self
162 }
163
164 pub fn outline(&mut self, outline: Vec<ClosedVectorPath>) -> &mut Self {
165 self.inner.outline = outline;
166 self
167 }
168
169 pub fn thumbnail<T: AsRef<Thumbnail>>(&mut self, thumbnail: T) -> &mut Self {
170 self.inner.thumbnail = Some(thumbnail.as_ref().clone());
171 self
172 }
173
174 pub fn sticker<T: AsRef<File>>(&mut self, sticker: T) -> &mut Self {
175 self.inner.sticker = sticker.as_ref().clone();
176 self
177 }
178}
179
180impl AsRef<Sticker> for Sticker {
181 fn as_ref(&self) -> &Sticker {
182 self
183 }
184}
185
186impl AsRef<Sticker> for StickerBuilder {
187 fn as_ref(&self) -> &Sticker {
188 &self.inner
189 }
190}