rust_tdlib/types/
read_file_part.rs

1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5/// Reads a part of a file from the TDLib file cache and returns read bytes. This method is intended to be used only if the application has no direct access to TDLib's file system, because it is usually slower than a direct read from the file
6#[derive(Debug, Clone, Default, Serialize, Deserialize)]
7pub struct ReadFilePart {
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    /// Identifier of the file. The file must be located in the TDLib file cache
14
15    #[serde(default)]
16    file_id: i32,
17    /// The offset from which to read the file
18
19    #[serde(default)]
20    offset: i32,
21    /// Number of bytes to read. An error will be returned if there are not enough bytes available in the file from the specified position. Pass 0 to read all available data from the specified position
22
23    #[serde(default)]
24    count: i32,
25
26    #[serde(rename(serialize = "@type"))]
27    td_type: String,
28}
29
30impl RObject for ReadFilePart {
31    #[doc(hidden)]
32    fn extra(&self) -> Option<&str> {
33        self.extra.as_deref()
34    }
35    #[doc(hidden)]
36    fn client_id(&self) -> Option<i32> {
37        self.client_id
38    }
39}
40
41impl RFunction for ReadFilePart {}
42
43impl ReadFilePart {
44    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
45        Ok(serde_json::from_str(json.as_ref())?)
46    }
47    pub fn builder() -> ReadFilePartBuilder {
48        let mut inner = ReadFilePart::default();
49        inner.extra = Some(Uuid::new_v4().to_string());
50
51        inner.td_type = "readFilePart".to_string();
52
53        ReadFilePartBuilder { inner }
54    }
55
56    pub fn file_id(&self) -> i32 {
57        self.file_id
58    }
59
60    pub fn offset(&self) -> i32 {
61        self.offset
62    }
63
64    pub fn count(&self) -> i32 {
65        self.count
66    }
67}
68
69#[doc(hidden)]
70pub struct ReadFilePartBuilder {
71    inner: ReadFilePart,
72}
73
74#[deprecated]
75pub type RTDReadFilePartBuilder = ReadFilePartBuilder;
76
77impl ReadFilePartBuilder {
78    pub fn build(&self) -> ReadFilePart {
79        self.inner.clone()
80    }
81
82    pub fn file_id(&mut self, file_id: i32) -> &mut Self {
83        self.inner.file_id = file_id;
84        self
85    }
86
87    pub fn offset(&mut self, offset: i32) -> &mut Self {
88        self.inner.offset = offset;
89        self
90    }
91
92    pub fn count(&mut self, count: i32) -> &mut Self {
93        self.inner.count = count;
94        self
95    }
96}
97
98impl AsRef<ReadFilePart> for ReadFilePart {
99    fn as_ref(&self) -> &ReadFilePart {
100        self
101    }
102}
103
104impl AsRef<ReadFilePart> for ReadFilePartBuilder {
105    fn as_ref(&self) -> &ReadFilePart {
106        &self.inner
107    }
108}