rtdlib/types/
animation.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Describes an animation file. The animation must be encoded in GIF or MPEG4 format
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct Animation {
12  #[doc(hidden)]
13  #[serde(rename(serialize = "@type", deserialize = "@type"))]
14  td_name: String,
15  #[doc(hidden)]
16  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17  extra: Option<String>,
18  /// Duration of the animation, in seconds; as defined by the sender
19  duration: i64,
20  /// Width of the animation
21  width: i64,
22  /// Height of the animation
23  height: i64,
24  /// Original name of the file; as defined by the sender
25  file_name: String,
26  /// MIME type of the file, usually "image/gif" or "video/mp4"
27  mime_type: String,
28  /// True, if stickers were added to the animation. The list of corresponding sticker set can be received using getAttachedStickerSets
29  has_stickers: bool,
30  /// Animation minithumbnail; may be null
31  minithumbnail: Option<Minithumbnail>,
32  /// Animation thumbnail in JPEG or MPEG4 format; may be null
33  thumbnail: Option<Thumbnail>,
34  /// File containing the animation
35  animation: File,
36  
37}
38
39impl RObject for Animation {
40  #[doc(hidden)] fn td_name(&self) -> &'static str { "animation" }
41  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
42  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
43}
44
45
46
47impl Animation {
48  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
49  pub fn builder() -> RTDAnimationBuilder {
50    let mut inner = Animation::default();
51    inner.td_name = "animation".to_string();
52    inner.extra = Some(Uuid::new_v4().to_string());
53    RTDAnimationBuilder { inner }
54  }
55
56  pub fn duration(&self) -> i64 { self.duration }
57
58  pub fn width(&self) -> i64 { self.width }
59
60  pub fn height(&self) -> i64 { self.height }
61
62  pub fn file_name(&self) -> &String { &self.file_name }
63
64  pub fn mime_type(&self) -> &String { &self.mime_type }
65
66  pub fn has_stickers(&self) -> bool { self.has_stickers }
67
68  pub fn minithumbnail(&self) -> &Option<Minithumbnail> { &self.minithumbnail }
69
70  pub fn thumbnail(&self) -> &Option<Thumbnail> { &self.thumbnail }
71
72  pub fn animation(&self) -> &File { &self.animation }
73
74}
75
76#[doc(hidden)]
77pub struct RTDAnimationBuilder {
78  inner: Animation
79}
80
81impl RTDAnimationBuilder {
82  pub fn build(&self) -> Animation { self.inner.clone() }
83
84   
85  pub fn duration(&mut self, duration: i64) -> &mut Self {
86    self.inner.duration = duration;
87    self
88  }
89
90   
91  pub fn width(&mut self, width: i64) -> &mut Self {
92    self.inner.width = width;
93    self
94  }
95
96   
97  pub fn height(&mut self, height: i64) -> &mut Self {
98    self.inner.height = height;
99    self
100  }
101
102   
103  pub fn file_name<T: AsRef<str>>(&mut self, file_name: T) -> &mut Self {
104    self.inner.file_name = file_name.as_ref().to_string();
105    self
106  }
107
108   
109  pub fn mime_type<T: AsRef<str>>(&mut self, mime_type: T) -> &mut Self {
110    self.inner.mime_type = mime_type.as_ref().to_string();
111    self
112  }
113
114   
115  pub fn has_stickers(&mut self, has_stickers: bool) -> &mut Self {
116    self.inner.has_stickers = has_stickers;
117    self
118  }
119
120   
121  pub fn minithumbnail<T: AsRef<Minithumbnail>>(&mut self, minithumbnail: T) -> &mut Self {
122    self.inner.minithumbnail = Some(minithumbnail.as_ref().clone());
123    self
124  }
125
126   
127  pub fn thumbnail<T: AsRef<Thumbnail>>(&mut self, thumbnail: T) -> &mut Self {
128    self.inner.thumbnail = Some(thumbnail.as_ref().clone());
129    self
130  }
131
132   
133  pub fn animation<T: AsRef<File>>(&mut self, animation: T) -> &mut Self {
134    self.inner.animation = animation.as_ref().clone();
135    self
136  }
137
138}
139
140impl AsRef<Animation> for Animation {
141  fn as_ref(&self) -> &Animation { self }
142}
143
144impl AsRef<Animation> for RTDAnimationBuilder {
145  fn as_ref(&self) -> &Animation { &self.inner }
146}
147
148
149