telegram_bot_async_raw/requests/
get_file.rs

1use crate::{requests::*, types::*};
2
3/// Use this method to get basic info about a file and prepare it for downloading.
4/// For the moment, bots can download files of up to 20MB in size.
5#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
6#[must_use = "requests do nothing unless sent"]
7pub struct GetFile {
8    file_id: FileRef,
9}
10
11impl<'s> Request for GetFile {
12    type Type = JsonRequestType<Self>;
13    type Response = JsonIdResponse<File>;
14
15    fn serialize(&self) -> Result<HttpRequest, Error> {
16        Self::Type::serialize(RequestUrl::method("getFile"), self)
17    }
18}
19
20impl GetFile {
21    pub fn new<F>(file: F) -> Self
22    where
23        F: ToFileRef,
24    {
25        Self {
26            file_id: file.to_file_ref(),
27        }
28    }
29}
30
31/// Get basic info about a file and prepare it for downloading.
32pub trait CanGetFile {
33    fn get_file(&self) -> GetFile;
34}
35
36impl<F> CanGetFile for F
37where
38    F: ToFileRef,
39{
40    fn get_file(&self) -> GetFile {
41        GetFile::new(self)
42    }
43}