diff --git a/src/net/download.rs b/src/net/download.rs index dcef724f..685d9f57 100644 --- a/src/net/download.rs +++ b/src/net/download.rs @@ -34,17 +34,17 @@ pub trait Download<'w> /// use teloxide_core::{ /// net::Download, /// requests::{Request, Requester}, - /// types::File as TgFile, + /// types::File, /// Bot, /// }; - /// use tokio::fs::File; + /// use tokio::fs; /// /// # async fn run() -> Result<(), Box> { /// let bot = Bot::new("TOKEN"); /// - /// let TgFile { file_path, .. } = bot.get_file("*file_id*").await?; - /// let mut file = File::create("/tmp/test.png").await?; - /// bot.download_file(&file_path, &mut file).await?; + /// let file = bot.get_file("*file_id*").await?; + /// let mut dst = fs::File::create("/tmp/test.png").await?; + /// bot.download_file(&file.path, &mut dst).await?; /// # Ok(()) } /// ``` /// diff --git a/src/types/animation.rs b/src/types/animation.rs index beb032db..22aa8a46 100644 --- a/src/types/animation.rs +++ b/src/types/animation.rs @@ -1,4 +1,3 @@ -use derive_more::Deref; use mime::Mime; use serde::{Deserialize, Serialize}; @@ -9,10 +8,9 @@ use crate::types::{FileMeta, PhotoSize}; /// /// [The official docs](https://core.telegram.org/bots/api#animation). #[serde_with_macros::skip_serializing_none] -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Deref)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Animation { /// Metadata of the animation file. - #[deref] #[serde(flatten)] pub file: FileMeta, @@ -62,18 +60,18 @@ mod tests { "file_size":6500}"#; let expected = Animation { file: FileMeta { - file_id: "id".to_string(), - file_unique_id: "".to_string(), - file_size: 6500, + id: "id".to_string(), + unique_id: "".to_string(), + size: 6500, }, width: 320, height: 320, duration: 59, thumb: Some(PhotoSize { file: FileMeta { - file_id: "id".to_owned(), - file_unique_id: "".to_owned(), - file_size: 3452, + id: "id".to_owned(), + unique_id: "".to_owned(), + size: 3452, }, width: 320, height: 320, diff --git a/src/types/audio.rs b/src/types/audio.rs index 1f17690a..ee7d7468 100644 --- a/src/types/audio.rs +++ b/src/types/audio.rs @@ -1,4 +1,3 @@ -use derive_more::Deref; use mime::Mime; use serde::{Deserialize, Serialize}; @@ -9,10 +8,9 @@ use crate::types::{FileMeta, PhotoSize}; /// /// [The official docs](https://core.telegram.org/bots/api#audio). #[serde_with_macros::skip_serializing_none] -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Deref)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Audio { /// Metadata of the audio file. - #[deref] #[serde(flatten)] pub file: FileMeta, @@ -62,9 +60,9 @@ mod tests { }"#; let expected = Audio { file: FileMeta { - file_id: "id".to_string(), - file_unique_id: "".to_string(), - file_size: 123_456, + id: "id".to_string(), + unique_id: "".to_string(), + size: 123_456, }, duration: 60, performer: Some("Performer".to_string()), @@ -72,9 +70,9 @@ mod tests { mime_type: Some("application/zip".parse().unwrap()), thumb: Some(PhotoSize { file: FileMeta { - file_id: "id".to_owned(), - file_unique_id: "".to_owned(), - file_size: 3452, + id: "id".to_owned(), + unique_id: "".to_owned(), + size: 3452, }, width: 320, height: 320, diff --git a/src/types/document.rs b/src/types/document.rs index 035cdd41..4ad439ae 100644 --- a/src/types/document.rs +++ b/src/types/document.rs @@ -1,4 +1,3 @@ -use derive_more::Deref; use mime::Mime; use serde::{Deserialize, Serialize}; @@ -13,10 +12,9 @@ use crate::types::{FileMeta, PhotoSize}; /// [voice messages]: https://core.telegram.org/bots/api#voice /// [audio files]: https://core.telegram.org/bots/api#audio #[serde_with_macros::skip_serializing_none] -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Deref)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Document { /// Metadata of the document file. - #[deref] #[serde(flatten)] pub file: FileMeta, diff --git a/src/types/file.rs b/src/types/file.rs index 892b382c..89ae95f7 100644 --- a/src/types/file.rs +++ b/src/types/file.rs @@ -25,26 +25,30 @@ pub struct File { /// File path. Use [`Bot::download_file(file_path, dst)`] to get the file. /// /// [`Bot::download_file(file_path, dst)`]: crate::net::Download::download_file - pub file_path: String, + #[serde(rename = "file_path")] + pub path: String, } -/// Metadata of the [`File`]. +/// Metadata of a [`File`]. #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct FileMeta { /// Identifier for this file. - pub file_id: String, + #[serde(rename = "file_id")] + pub id: String, /// Unique identifier for this file, which is supposed to be the same over /// time and for different bots. Can't be used to download or reuse the /// file. - pub file_unique_id: String, + #[serde(rename = "file_unique_id")] + pub unique_id: String, /// File size in bytes. - // This should never be necessary in practice, + #[serde(rename = "file_size")] + // This fallback should never be necessary in practice, // but just in case something goes wrong with the TBA server // (see the test below) #[serde(default = "file_size_fallback")] - pub file_size: u32, + pub size: u32, } pub(crate) const fn file_size_fallback() -> u32 { @@ -58,12 +62,12 @@ pub(crate) const fn file_size_fallback() -> u32 { /// ```rust /// use teloxide_core::types::File; /// # -/// # let get_file = || File { meta: teloxide_core::types::FileMeta { file_id: String::new(), file_unique_id: String::new(), file_size: 0 }, file_path: String::new() }; +/// # let get_file = || File { meta: teloxide_core::types::FileMeta { id: String::new(), unique_id: String::new(), size: 0 }, path: String::new() }; /// let file: File = get_file(); /// -/// let file_id: &str = &file.file_id; -/// let file_unique_id: &str = &file.file_unique_id; -/// let file_size: u32 = file.file_size; +/// let file_id: &str = &file.id; +/// let file_unique_id: &str = &file.unique_id; +/// let file_size: u32 = file.size; /// # /// # let _ = (file_id, file_unique_id, file_size); /// ``` @@ -92,11 +96,11 @@ mod tests { file, File { meta: FileMeta { - file_id: "FILE_ID".to_owned(), - file_unique_id: "FILE_UNIQUE_ID".to_owned(), - file_size: u32::MAX, + id: "FILE_ID".to_owned(), + unique_id: "FILE_UNIQUE_ID".to_owned(), + size: u32::MAX, }, - file_path: "FILE_PATH".to_owned(), + path: "FILE_PATH".to_owned(), } ); } @@ -111,9 +115,9 @@ mod tests { assert_eq!( file, FileMeta { - file_id: "FILE_ID".to_owned(), - file_unique_id: "FILE_UNIQUE_ID".to_owned(), - file_size: 42, + id: "FILE_ID".to_owned(), + unique_id: "FILE_UNIQUE_ID".to_owned(), + size: 42, } ); } @@ -127,11 +131,11 @@ mod tests { file, File { meta: FileMeta { - file_id: "FILE_ID".to_owned(), - file_unique_id: "FILE_UNIQUE_ID".to_owned(), - file_size: 42, + id: "FILE_ID".to_owned(), + unique_id: "FILE_UNIQUE_ID".to_owned(), + size: 42, }, - file_path: "FILE_PATH".to_owned(), + path: "FILE_PATH".to_owned(), } ); } diff --git a/src/types/passport_file.rs b/src/types/passport_file.rs index 935b3567..05b97225 100644 --- a/src/types/passport_file.rs +++ b/src/types/passport_file.rs @@ -19,5 +19,6 @@ pub struct PassportFile { /// Time when the file was uploaded. #[serde(with = "crate::types::serde_date_from_unix_timestamp")] - pub file_date: DateTime, + #[serde(rename = "file_date")] + pub date: DateTime, } diff --git a/src/types/photo_size.rs b/src/types/photo_size.rs index 5e030bd1..9b0af706 100644 --- a/src/types/photo_size.rs +++ b/src/types/photo_size.rs @@ -1,4 +1,3 @@ -use derive_more::Deref; use serde::{Deserialize, Serialize}; use crate::types::FileMeta; @@ -8,10 +7,9 @@ use crate::types::FileMeta; /// [file]: crate::types::Document /// [sticker]: crate::types::Sticker #[serde_with_macros::skip_serializing_none] -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Deref)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct PhotoSize { /// Metadata of the photo file. - #[deref] #[serde(flatten)] pub file: FileMeta, @@ -32,9 +30,9 @@ mod tests { "file_size":3452}"#; let expected = PhotoSize { file: FileMeta { - file_id: "id".to_owned(), - file_unique_id: "".to_owned(), - file_size: 3452, + id: "id".to_owned(), + unique_id: "".to_owned(), + size: 3452, }, width: 320, height: 320, diff --git a/src/types/sticker.rs b/src/types/sticker.rs index 4ee875fd..dd5c651e 100644 --- a/src/types/sticker.rs +++ b/src/types/sticker.rs @@ -364,8 +364,8 @@ mod tests { assert_eq!(sticker.mask_position().unwrap().point, MaskPoint::Forehead); assert_eq!(sticker.is_animated(), false); assert_eq!(sticker.is_video(), false); - assert_eq!(sticker.thumb.clone().unwrap().file_size, 11028); - assert_eq!(sticker.file.file_size, 18290); + assert_eq!(sticker.thumb.clone().unwrap().file.size, 11028); + assert_eq!(sticker.file.size, 18290); assert_eq!(sticker.width, 512); assert_eq!(sticker.height, 512); @@ -404,8 +404,8 @@ mod tests { assert_eq!(sticker.premium_animation(), None); assert_eq!(sticker.is_animated(), false); assert_eq!(sticker.is_video(), false); - assert_eq!(sticker.thumb.clone().unwrap().file_size, 4558); - assert_eq!(sticker.file.file_size, 25734); + assert_eq!(sticker.thumb.clone().unwrap().file.size, 4558); + assert_eq!(sticker.file.size, 25734); assert_eq!(sticker.width, 463); assert_eq!(sticker.height, 512); assert_eq!(sticker.set_name.as_deref(), Some("menhera2")); diff --git a/src/types/video.rs b/src/types/video.rs index e4bc736b..e127167b 100644 --- a/src/types/video.rs +++ b/src/types/video.rs @@ -1,4 +1,3 @@ -use derive_more::Deref; use mime::Mime; use serde::{Deserialize, Serialize}; @@ -8,10 +7,9 @@ use crate::types::{FileMeta, PhotoSize}; /// /// [The official docs](https://core.telegram.org/bots/api#video). #[serde_with_macros::skip_serializing_none] -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Deref)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Video { /// Metadata of the video file. - #[deref] #[serde(flatten)] pub file: FileMeta, diff --git a/src/types/video_note.rs b/src/types/video_note.rs index 9b82c643..d112c672 100644 --- a/src/types/video_note.rs +++ b/src/types/video_note.rs @@ -1,4 +1,3 @@ -use derive_more::Deref; use serde::{Deserialize, Serialize}; use crate::types::{FileMeta, PhotoSize}; @@ -11,10 +10,9 @@ use crate::types::{FileMeta, PhotoSize}; /// [video message]: https://telegram.org/blog/video-messages-and-telescope /// [v4.0]: https://telegram.org/blog/video-messages-and-telescope #[serde_with_macros::skip_serializing_none] -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Deref)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct VideoNote { /// Metadata of the video note file. - #[deref] #[serde(flatten)] pub file: FileMeta, diff --git a/src/types/voice.rs b/src/types/voice.rs index f124e08d..0dbcd7b8 100644 --- a/src/types/voice.rs +++ b/src/types/voice.rs @@ -1,4 +1,3 @@ -use derive_more::Deref; use mime::Mime; use serde::{Deserialize, Serialize}; @@ -8,10 +7,9 @@ use crate::types::FileMeta; /// /// [The official docs](https://core.telegram.org/bots/api#voice). #[serde_with_macros::skip_serializing_none] -#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, Deref)] +#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)] pub struct Voice { /// Metadata of the voice file. - #[deref] #[serde(flatten)] pub file: FileMeta,