rust_tdlib/types/
background_fill.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7pub trait TDBackgroundFill: Debug + RObject {}
9
10#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum BackgroundFill {
14 #[doc(hidden)]
15 #[default]
16 _Default,
17 #[serde(rename = "backgroundFillFreeformGradient")]
19 FreeformGradient(BackgroundFillFreeformGradient),
20 #[serde(rename = "backgroundFillGradient")]
22 Gradient(BackgroundFillGradient),
23 #[serde(rename = "backgroundFillSolid")]
25 Solid(BackgroundFillSolid),
26}
27
28impl RObject for BackgroundFill {
29 #[doc(hidden)]
30 fn extra(&self) -> Option<&str> {
31 match self {
32 BackgroundFill::FreeformGradient(t) => t.extra(),
33 BackgroundFill::Gradient(t) => t.extra(),
34 BackgroundFill::Solid(t) => t.extra(),
35
36 _ => None,
37 }
38 }
39 #[doc(hidden)]
40 fn client_id(&self) -> Option<i32> {
41 match self {
42 BackgroundFill::FreeformGradient(t) => t.client_id(),
43 BackgroundFill::Gradient(t) => t.client_id(),
44 BackgroundFill::Solid(t) => t.client_id(),
45
46 _ => None,
47 }
48 }
49}
50
51impl BackgroundFill {
52 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
53 Ok(serde_json::from_str(json.as_ref())?)
54 }
55 #[doc(hidden)]
56 pub fn _is_default(&self) -> bool {
57 matches!(self, BackgroundFill::_Default)
58 }
59}
60
61impl AsRef<BackgroundFill> for BackgroundFill {
62 fn as_ref(&self) -> &BackgroundFill {
63 self
64 }
65}
66
67#[derive(Debug, Clone, Default, Serialize, Deserialize)]
69pub struct BackgroundFillFreeformGradient {
70 #[doc(hidden)]
71 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
72 extra: Option<String>,
73 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
74 client_id: Option<i32>,
75 #[serde(default)]
78 colors: Vec<i32>,
79}
80
81impl RObject for BackgroundFillFreeformGradient {
82 #[doc(hidden)]
83 fn extra(&self) -> Option<&str> {
84 self.extra.as_deref()
85 }
86 #[doc(hidden)]
87 fn client_id(&self) -> Option<i32> {
88 self.client_id
89 }
90}
91
92impl TDBackgroundFill for BackgroundFillFreeformGradient {}
93
94impl BackgroundFillFreeformGradient {
95 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
96 Ok(serde_json::from_str(json.as_ref())?)
97 }
98 pub fn builder() -> BackgroundFillFreeformGradientBuilder {
99 let mut inner = BackgroundFillFreeformGradient::default();
100 inner.extra = Some(Uuid::new_v4().to_string());
101
102 BackgroundFillFreeformGradientBuilder { inner }
103 }
104
105 pub fn colors(&self) -> &Vec<i32> {
106 &self.colors
107 }
108}
109
110#[doc(hidden)]
111pub struct BackgroundFillFreeformGradientBuilder {
112 inner: BackgroundFillFreeformGradient,
113}
114
115#[deprecated]
116pub type RTDBackgroundFillFreeformGradientBuilder = BackgroundFillFreeformGradientBuilder;
117
118impl BackgroundFillFreeformGradientBuilder {
119 pub fn build(&self) -> BackgroundFillFreeformGradient {
120 self.inner.clone()
121 }
122
123 pub fn colors(&mut self, colors: Vec<i32>) -> &mut Self {
124 self.inner.colors = colors;
125 self
126 }
127}
128
129impl AsRef<BackgroundFillFreeformGradient> for BackgroundFillFreeformGradient {
130 fn as_ref(&self) -> &BackgroundFillFreeformGradient {
131 self
132 }
133}
134
135impl AsRef<BackgroundFillFreeformGradient> for BackgroundFillFreeformGradientBuilder {
136 fn as_ref(&self) -> &BackgroundFillFreeformGradient {
137 &self.inner
138 }
139}
140
141#[derive(Debug, Clone, Default, Serialize, Deserialize)]
143pub struct BackgroundFillGradient {
144 #[doc(hidden)]
145 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
146 extra: Option<String>,
147 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
148 client_id: Option<i32>,
149 #[serde(default)]
152 top_color: i32,
153 #[serde(default)]
156 bottom_color: i32,
157 #[serde(default)]
160 rotation_angle: i32,
161}
162
163impl RObject for BackgroundFillGradient {
164 #[doc(hidden)]
165 fn extra(&self) -> Option<&str> {
166 self.extra.as_deref()
167 }
168 #[doc(hidden)]
169 fn client_id(&self) -> Option<i32> {
170 self.client_id
171 }
172}
173
174impl TDBackgroundFill for BackgroundFillGradient {}
175
176impl BackgroundFillGradient {
177 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
178 Ok(serde_json::from_str(json.as_ref())?)
179 }
180 pub fn builder() -> BackgroundFillGradientBuilder {
181 let mut inner = BackgroundFillGradient::default();
182 inner.extra = Some(Uuid::new_v4().to_string());
183
184 BackgroundFillGradientBuilder { inner }
185 }
186
187 pub fn top_color(&self) -> i32 {
188 self.top_color
189 }
190
191 pub fn bottom_color(&self) -> i32 {
192 self.bottom_color
193 }
194
195 pub fn rotation_angle(&self) -> i32 {
196 self.rotation_angle
197 }
198}
199
200#[doc(hidden)]
201pub struct BackgroundFillGradientBuilder {
202 inner: BackgroundFillGradient,
203}
204
205#[deprecated]
206pub type RTDBackgroundFillGradientBuilder = BackgroundFillGradientBuilder;
207
208impl BackgroundFillGradientBuilder {
209 pub fn build(&self) -> BackgroundFillGradient {
210 self.inner.clone()
211 }
212
213 pub fn top_color(&mut self, top_color: i32) -> &mut Self {
214 self.inner.top_color = top_color;
215 self
216 }
217
218 pub fn bottom_color(&mut self, bottom_color: i32) -> &mut Self {
219 self.inner.bottom_color = bottom_color;
220 self
221 }
222
223 pub fn rotation_angle(&mut self, rotation_angle: i32) -> &mut Self {
224 self.inner.rotation_angle = rotation_angle;
225 self
226 }
227}
228
229impl AsRef<BackgroundFillGradient> for BackgroundFillGradient {
230 fn as_ref(&self) -> &BackgroundFillGradient {
231 self
232 }
233}
234
235impl AsRef<BackgroundFillGradient> for BackgroundFillGradientBuilder {
236 fn as_ref(&self) -> &BackgroundFillGradient {
237 &self.inner
238 }
239}
240
241#[derive(Debug, Clone, Default, Serialize, Deserialize)]
243pub struct BackgroundFillSolid {
244 #[doc(hidden)]
245 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
246 extra: Option<String>,
247 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
248 client_id: Option<i32>,
249 #[serde(default)]
252 color: i32,
253}
254
255impl RObject for BackgroundFillSolid {
256 #[doc(hidden)]
257 fn extra(&self) -> Option<&str> {
258 self.extra.as_deref()
259 }
260 #[doc(hidden)]
261 fn client_id(&self) -> Option<i32> {
262 self.client_id
263 }
264}
265
266impl TDBackgroundFill for BackgroundFillSolid {}
267
268impl BackgroundFillSolid {
269 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
270 Ok(serde_json::from_str(json.as_ref())?)
271 }
272 pub fn builder() -> BackgroundFillSolidBuilder {
273 let mut inner = BackgroundFillSolid::default();
274 inner.extra = Some(Uuid::new_v4().to_string());
275
276 BackgroundFillSolidBuilder { inner }
277 }
278
279 pub fn color(&self) -> i32 {
280 self.color
281 }
282}
283
284#[doc(hidden)]
285pub struct BackgroundFillSolidBuilder {
286 inner: BackgroundFillSolid,
287}
288
289#[deprecated]
290pub type RTDBackgroundFillSolidBuilder = BackgroundFillSolidBuilder;
291
292impl BackgroundFillSolidBuilder {
293 pub fn build(&self) -> BackgroundFillSolid {
294 self.inner.clone()
295 }
296
297 pub fn color(&mut self, color: i32) -> &mut Self {
298 self.inner.color = color;
299 self
300 }
301}
302
303impl AsRef<BackgroundFillSolid> for BackgroundFillSolid {
304 fn as_ref(&self) -> &BackgroundFillSolid {
305 self
306 }
307}
308
309impl AsRef<BackgroundFillSolid> for BackgroundFillSolidBuilder {
310 fn as_ref(&self) -> &BackgroundFillSolid {
311 &self.inner
312 }
313}