rtdlib/types/
video_note.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Describes a video note. The video must be equal in width and height, cropped to a circle, and stored in MPEG4 format
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct VideoNote {
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 and height; as defined by the sender
21  length: i64,
22  /// Video minithumbnail; may be null
23  minithumbnail: Option<Minithumbnail>,
24  /// Video thumbnail in JPEG format; as defined by the sender; may be null
25  thumbnail: Option<Thumbnail>,
26  /// File containing the video
27  video: File,
28  
29}
30
31impl RObject for VideoNote {
32  #[doc(hidden)] fn td_name(&self) -> &'static str { "videoNote" }
33  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
34  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
35}
36
37
38
39impl VideoNote {
40  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
41  pub fn builder() -> RTDVideoNoteBuilder {
42    let mut inner = VideoNote::default();
43    inner.td_name = "videoNote".to_string();
44    inner.extra = Some(Uuid::new_v4().to_string());
45    RTDVideoNoteBuilder { inner }
46  }
47
48  pub fn duration(&self) -> i64 { self.duration }
49
50  pub fn length(&self) -> i64 { self.length }
51
52  pub fn minithumbnail(&self) -> &Option<Minithumbnail> { &self.minithumbnail }
53
54  pub fn thumbnail(&self) -> &Option<Thumbnail> { &self.thumbnail }
55
56  pub fn video(&self) -> &File { &self.video }
57
58}
59
60#[doc(hidden)]
61pub struct RTDVideoNoteBuilder {
62  inner: VideoNote
63}
64
65impl RTDVideoNoteBuilder {
66  pub fn build(&self) -> VideoNote { self.inner.clone() }
67
68   
69  pub fn duration(&mut self, duration: i64) -> &mut Self {
70    self.inner.duration = duration;
71    self
72  }
73
74   
75  pub fn length(&mut self, length: i64) -> &mut Self {
76    self.inner.length = length;
77    self
78  }
79
80   
81  pub fn minithumbnail<T: AsRef<Minithumbnail>>(&mut self, minithumbnail: T) -> &mut Self {
82    self.inner.minithumbnail = Some(minithumbnail.as_ref().clone());
83    self
84  }
85
86   
87  pub fn thumbnail<T: AsRef<Thumbnail>>(&mut self, thumbnail: T) -> &mut Self {
88    self.inner.thumbnail = Some(thumbnail.as_ref().clone());
89    self
90  }
91
92   
93  pub fn video<T: AsRef<File>>(&mut self, video: T) -> &mut Self {
94    self.inner.video = video.as_ref().clone();
95    self
96  }
97
98}
99
100impl AsRef<VideoNote> for VideoNote {
101  fn as_ref(&self) -> &VideoNote { self }
102}
103
104impl AsRef<VideoNote> for RTDVideoNoteBuilder {
105  fn as_ref(&self) -> &VideoNote { &self.inner }
106}
107
108
109