rtdlib/types/
input_personal_document.rs

1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9/// A personal document to be saved to Telegram Passport
10#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct InputPersonalDocument {
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  /// List of files containing the pages of the document
19  files: Vec<InputFile>,
20  /// List of files containing a certified English translation of the document
21  translation: Vec<InputFile>,
22  
23}
24
25impl RObject for InputPersonalDocument {
26  #[doc(hidden)] fn td_name(&self) -> &'static str { "inputPersonalDocument" }
27  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
28  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
29}
30
31
32
33impl InputPersonalDocument {
34  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
35  pub fn builder() -> RTDInputPersonalDocumentBuilder {
36    let mut inner = InputPersonalDocument::default();
37    inner.td_name = "inputPersonalDocument".to_string();
38    inner.extra = Some(Uuid::new_v4().to_string());
39    RTDInputPersonalDocumentBuilder { inner }
40  }
41
42  pub fn files(&self) -> &Vec<InputFile> { &self.files }
43
44  pub fn translation(&self) -> &Vec<InputFile> { &self.translation }
45
46}
47
48#[doc(hidden)]
49pub struct RTDInputPersonalDocumentBuilder {
50  inner: InputPersonalDocument
51}
52
53impl RTDInputPersonalDocumentBuilder {
54  pub fn build(&self) -> InputPersonalDocument { self.inner.clone() }
55
56   
57  pub fn files(&mut self, files: Vec<InputFile>) -> &mut Self {
58    self.inner.files = files;
59    self
60  }
61
62   
63  pub fn translation(&mut self, translation: Vec<InputFile>) -> &mut Self {
64    self.inner.translation = translation;
65    self
66  }
67
68}
69
70impl AsRef<InputPersonalDocument> for InputPersonalDocument {
71  fn as_ref(&self) -> &InputPersonalDocument { self }
72}
73
74impl AsRef<InputPersonalDocument> for RTDInputPersonalDocumentBuilder {
75  fn as_ref(&self) -> &InputPersonalDocument { &self.inner }
76}
77
78
79