rtdlib/types/
file_part.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// Contains a part of a file
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct FilePart {
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  /// File bytes
19  data: String,
20  
21}
22
23impl RObject for FilePart {
24  #[doc(hidden)] fn td_name(&self) -> &'static str { "filePart" }
25  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
26  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
27}
28
29
30
31impl FilePart {
32  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
33  pub fn builder() -> RTDFilePartBuilder {
34    let mut inner = FilePart::default();
35    inner.td_name = "filePart".to_string();
36    inner.extra = Some(Uuid::new_v4().to_string());
37    RTDFilePartBuilder { inner }
38  }
39
40  pub fn data(&self) -> &String { &self.data }
41
42}
43
44#[doc(hidden)]
45pub struct RTDFilePartBuilder {
46  inner: FilePart
47}
48
49impl RTDFilePartBuilder {
50  pub fn build(&self) -> FilePart { self.inner.clone() }
51
52   
53  pub fn data<T: AsRef<str>>(&mut self, data: T) -> &mut Self {
54    self.inner.data = data.as_ref().to_string();
55    self
56  }
57
58}
59
60impl AsRef<FilePart> for FilePart {
61  fn as_ref(&self) -> &FilePart { self }
62}
63
64impl AsRef<FilePart> for RTDFilePartBuilder {
65  fn as_ref(&self) -> &FilePart { &self.inner }
66}
67
68
69