rust_tdlib/types/
download_file.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct DownloadFile {
8 #[doc(hidden)]
9 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
10 extra: Option<String>,
11 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
12 client_id: Option<i32>,
13 #[serde(default)]
16 file_id: i32,
17 #[serde(default)]
20 priority: i32,
21 #[serde(default)]
24 offset: i32,
25 #[serde(default)]
28 limit: i32,
29 #[serde(default)]
32 synchronous: bool,
33
34 #[serde(rename(serialize = "@type"))]
35 td_type: String,
36}
37
38impl RObject for DownloadFile {
39 #[doc(hidden)]
40 fn extra(&self) -> Option<&str> {
41 self.extra.as_deref()
42 }
43 #[doc(hidden)]
44 fn client_id(&self) -> Option<i32> {
45 self.client_id
46 }
47}
48
49impl RFunction for DownloadFile {}
50
51impl DownloadFile {
52 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
53 Ok(serde_json::from_str(json.as_ref())?)
54 }
55 pub fn builder() -> DownloadFileBuilder {
56 let mut inner = DownloadFile::default();
57 inner.extra = Some(Uuid::new_v4().to_string());
58
59 inner.td_type = "downloadFile".to_string();
60
61 DownloadFileBuilder { inner }
62 }
63
64 pub fn file_id(&self) -> i32 {
65 self.file_id
66 }
67
68 pub fn priority(&self) -> i32 {
69 self.priority
70 }
71
72 pub fn offset(&self) -> i32 {
73 self.offset
74 }
75
76 pub fn limit(&self) -> i32 {
77 self.limit
78 }
79
80 pub fn synchronous(&self) -> bool {
81 self.synchronous
82 }
83}
84
85#[doc(hidden)]
86pub struct DownloadFileBuilder {
87 inner: DownloadFile,
88}
89
90#[deprecated]
91pub type RTDDownloadFileBuilder = DownloadFileBuilder;
92
93impl DownloadFileBuilder {
94 pub fn build(&self) -> DownloadFile {
95 self.inner.clone()
96 }
97
98 pub fn file_id(&mut self, file_id: i32) -> &mut Self {
99 self.inner.file_id = file_id;
100 self
101 }
102
103 pub fn priority(&mut self, priority: i32) -> &mut Self {
104 self.inner.priority = priority;
105 self
106 }
107
108 pub fn offset(&mut self, offset: i32) -> &mut Self {
109 self.inner.offset = offset;
110 self
111 }
112
113 pub fn limit(&mut self, limit: i32) -> &mut Self {
114 self.inner.limit = limit;
115 self
116 }
117
118 pub fn synchronous(&mut self, synchronous: bool) -> &mut Self {
119 self.inner.synchronous = synchronous;
120 self
121 }
122}
123
124impl AsRef<DownloadFile> for DownloadFile {
125 fn as_ref(&self) -> &DownloadFile {
126 self
127 }
128}
129
130impl AsRef<DownloadFile> for DownloadFileBuilder {
131 fn as_ref(&self) -> &DownloadFile {
132 &self.inner
133 }
134}