rust_tdlib/types/
video.rs

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