rust_tdlib/types/
animation.rs

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