rtdlib/types/
thumbnail.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Represents a thumbnail
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct Thumbnail {
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  /// Thumbnail format
19  format: ThumbnailFormat,
20  /// Thumbnail width
21  width: i64,
22  /// Thumbnail height
23  height: i64,
24  /// The thumbnail
25  file: File,
26  
27}
28
29impl RObject for Thumbnail {
30  #[doc(hidden)] fn td_name(&self) -> &'static str { "thumbnail" }
31  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
32  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
33}
34
35
36
37impl Thumbnail {
38  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
39  pub fn builder() -> RTDThumbnailBuilder {
40    let mut inner = Thumbnail::default();
41    inner.td_name = "thumbnail".to_string();
42    inner.extra = Some(Uuid::new_v4().to_string());
43    RTDThumbnailBuilder { inner }
44  }
45
46  pub fn format(&self) -> &ThumbnailFormat { &self.format }
47
48  pub fn width(&self) -> i64 { self.width }
49
50  pub fn height(&self) -> i64 { self.height }
51
52  pub fn file(&self) -> &File { &self.file }
53
54}
55
56#[doc(hidden)]
57pub struct RTDThumbnailBuilder {
58  inner: Thumbnail
59}
60
61impl RTDThumbnailBuilder {
62  pub fn build(&self) -> Thumbnail { self.inner.clone() }
63
64   
65  pub fn format<T: AsRef<ThumbnailFormat>>(&mut self, format: T) -> &mut Self {
66    self.inner.format = format.as_ref().clone();
67    self
68  }
69
70   
71  pub fn width(&mut self, width: i64) -> &mut Self {
72    self.inner.width = width;
73    self
74  }
75
76   
77  pub fn height(&mut self, height: i64) -> &mut Self {
78    self.inner.height = height;
79    self
80  }
81
82   
83  pub fn file<T: AsRef<File>>(&mut self, file: T) -> &mut Self {
84    self.inner.file = file.as_ref().clone();
85    self
86  }
87
88}
89
90impl AsRef<Thumbnail> for Thumbnail {
91  fn as_ref(&self) -> &Thumbnail { self }
92}
93
94impl AsRef<Thumbnail> for RTDThumbnailBuilder {
95  fn as_ref(&self) -> &Thumbnail { &self.inner }
96}
97
98
99