rust_tdlib/types/
remote_file.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Represents a remote file
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct RemoteFile {
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    /// Remote file identifier; may be empty. Can be used by the current user across application restarts or even from other devices. Uniquely identifies a file, but a file can have a lot of different valid identifiers. If the ID starts with "http://" or "https://", it represents the HTTP URL of the file. TDLib is currently unable to download files if only their URL is known. If downloadFile is called on such a file or if it is sent to a secret chat, TDLib starts a file generation process by sending updateFileGenerationStart to the application with the HTTP URL in the original_path and "#url#" as the conversion string. Application must generate the file by downloading it to the specified location
14
15    #[serde(default)]
16    id: String,
17    /// Unique file identifier; may be empty if unknown. The unique file identifier which is the same for the same file even for different users and is persistent over time
18
19    #[serde(default)]
20    unique_id: String,
21    /// True, if the file is currently being uploaded (or a remote copy is being generated by some other means)
22
23    #[serde(default)]
24    is_uploading_active: bool,
25    /// True, if a remote copy is fully available
26
27    #[serde(default)]
28    is_uploading_completed: bool,
29    /// Size of the remote available part of the file, in bytes; 0 if unknown
30
31    #[serde(default)]
32    uploaded_size: i32,
33}
34
35impl RObject for RemoteFile {
36    #[doc(hidden)]
37    fn extra(&self) -> Option<&str> {
38        self.extra.as_deref()
39    }
40    #[doc(hidden)]
41    fn client_id(&self) -> Option<i32> {
42        self.client_id
43    }
44}
45
46impl RemoteFile {
47    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
48        Ok(serde_json::from_str(json.as_ref())?)
49    }
50    pub fn builder() -> RemoteFileBuilder {
51        let mut inner = RemoteFile::default();
52        inner.extra = Some(Uuid::new_v4().to_string());
53
54        RemoteFileBuilder { inner }
55    }
56
57    pub fn id(&self) -> &String {
58        &self.id
59    }
60
61    pub fn unique_id(&self) -> &String {
62        &self.unique_id
63    }
64
65    pub fn is_uploading_active(&self) -> bool {
66        self.is_uploading_active
67    }
68
69    pub fn is_uploading_completed(&self) -> bool {
70        self.is_uploading_completed
71    }
72
73    pub fn uploaded_size(&self) -> i32 {
74        self.uploaded_size
75    }
76}
77
78#[doc(hidden)]
79pub struct RemoteFileBuilder {
80    inner: RemoteFile,
81}
82
83#[deprecated]
84pub type RTDRemoteFileBuilder = RemoteFileBuilder;
85
86impl RemoteFileBuilder {
87    pub fn build(&self) -> RemoteFile {
88        self.inner.clone()
89    }
90
91    pub fn id<T: AsRef<str>>(&mut self, id: T) -> &mut Self {
92        self.inner.id = id.as_ref().to_string();
93        self
94    }
95
96    pub fn unique_id<T: AsRef<str>>(&mut self, unique_id: T) -> &mut Self {
97        self.inner.unique_id = unique_id.as_ref().to_string();
98        self
99    }
100
101    pub fn is_uploading_active(&mut self, is_uploading_active: bool) -> &mut Self {
102        self.inner.is_uploading_active = is_uploading_active;
103        self
104    }
105
106    pub fn is_uploading_completed(&mut self, is_uploading_completed: bool) -> &mut Self {
107        self.inner.is_uploading_completed = is_uploading_completed;
108        self
109    }
110
111    pub fn uploaded_size(&mut self, uploaded_size: i32) -> &mut Self {
112        self.inner.uploaded_size = uploaded_size;
113        self
114    }
115}
116
117impl AsRef<RemoteFile> for RemoteFile {
118    fn as_ref(&self) -> &RemoteFile {
119        self
120    }
121}
122
123impl AsRef<RemoteFile> for RemoteFileBuilder {
124    fn as_ref(&self) -> &RemoteFile {
125        &self.inner
126    }
127}