rtdlib/types/
video.rs

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