diff --git a/rustfmt.toml b/rustfmt.toml index 3d8f533d..f99a2b6f 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,4 @@ format_code_in_doc_comments = true wrap_comments = true -format_strings = true \ No newline at end of file +format_strings = true +max_width = 80 \ No newline at end of file diff --git a/src/bot/mod.rs b/src/bot/mod.rs index 7b390b38..bccc87da 100644 --- a/src/bot/mod.rs +++ b/src/bot/mod.rs @@ -1,11 +1,8 @@ use reqwest::r#async::Client; -use crate::core::requests::{ - get_me::GetMe, - send_message::SendMessage, - RequestInfo, - ChatId, -}; +use crate::core::requests::{ + get_me::GetMe, send_message::SendMessage, ChatId, RequestInfo, +}; pub struct Bot { token: String, @@ -23,7 +20,7 @@ impl Bot { pub fn with_client(token: &str, client: Client) -> Self { Bot { token: String::from(token), - client + client, } } } @@ -31,14 +28,22 @@ impl Bot { /// Telegram functions impl Bot { pub fn get_me(&self) -> GetMe { - GetMe::new(RequestInfo { token: &self.token, client: &self.client }) + GetMe::new(RequestInfo { + token: &self.token, + client: &self.client, + }) } pub fn send_message(&self, chat_id: C, text: T) -> SendMessage - where C: Into, T: Into + where + C: Into, + T: Into, { SendMessage::new( - RequestInfo { token: &self.token, client: &self.client }, + RequestInfo { + token: &self.token, + client: &self.client, + }, chat_id.into(), text.into(), ) diff --git a/src/core/requests/form_builder.rs b/src/core/requests/form_builder.rs index ba38bc19..e27f1d04 100644 --- a/src/core/requests/form_builder.rs +++ b/src/core/requests/form_builder.rs @@ -21,7 +21,8 @@ impl FormBuilder { Self { form: self.form.text( name.to_owned(), - serde_json::to_string(value).expect("serde_json::to_string failed"), + serde_json::to_string(value) + .expect("serde_json::to_string failed"), ), } } @@ -37,7 +38,8 @@ impl FormBuilder { Some(value) => Self { form: self.form.text( name.to_owned(), - serde_json::to_string(value).expect("serde_json::to_string failed"), + serde_json::to_string(value) + .expect("serde_json::to_string failed"), ), }, } diff --git a/src/core/requests/get_me.rs b/src/core/requests/get_me.rs index 6633d77a..74745bf8 100644 --- a/src/core/requests/get_me.rs +++ b/src/core/requests/get_me.rs @@ -1,5 +1,7 @@ use crate::core::network; -use crate::core::requests::{Request, RequestFuture, RequestInfo, ResponseResult}; +use crate::core::requests::{ + Request, RequestFuture, RequestInfo, ResponseResult, +}; use crate::core::types::User; #[derive(Debug)] @@ -12,7 +14,8 @@ impl<'a> Request<'a> for GetMe<'a> { fn send(self) -> RequestFuture<'a, ResponseResult> { Box::pin(async move { - network::request(self.info.client, self.info.token, "getMe", None).await + network::request(self.info.client, self.info.token, "getMe", None) + .await }) } } diff --git a/src/core/requests/send_message.rs b/src/core/requests/send_message.rs index 9df3ae59..40d2a46e 100644 --- a/src/core/requests/send_message.rs +++ b/src/core/requests/send_message.rs @@ -1,5 +1,7 @@ use crate::core::requests::form_builder::FormBuilder; -use crate::core::requests::{ChatId, Request, RequestFuture, RequestInfo, ResponseResult}; +use crate::core::requests::{ + ChatId, Request, RequestFuture, RequestInfo, ResponseResult, +}; use crate::core::{network, types::Message}; #[derive(Debug)] @@ -9,7 +11,8 @@ pub struct SendMessage<'a> { pub chat_id: ChatId, pub text: String, - pub parse_mode: Option, // TODO: ParseMode enum + pub parse_mode: Option, + // TODO: ParseMode enum pub disable_web_page_preview: Option, pub disable_notification: Option, pub reply_to_message_id: Option, @@ -29,8 +32,14 @@ impl<'a> Request<'a> for SendMessage<'a> { "disable_web_page_preview", self.disable_web_page_preview.as_ref(), ) - .add_if_some("disable_notification", self.disable_notification.as_ref()) - .add_if_some("reply_to_message_id", self.reply_to_message_id.as_ref()) + .add_if_some( + "disable_notification", + self.disable_notification.as_ref(), + ) + .add_if_some( + "reply_to_message_id", + self.reply_to_message_id.as_ref(), + ) .build(); network::request( @@ -45,7 +54,11 @@ impl<'a> Request<'a> for SendMessage<'a> { } impl<'a> SendMessage<'a> { - pub(crate) fn new(info: RequestInfo<'a>, chat_id: ChatId, text: String) -> Self { + pub(crate) fn new( + info: RequestInfo<'a>, + chat_id: ChatId, + text: String, + ) -> Self { SendMessage { info, chat_id, diff --git a/src/core/types/chat.rs b/src/core/types/chat.rs index 5eac8700..d808668f 100644 --- a/src/core/types/chat.rs +++ b/src/core/types/chat.rs @@ -59,10 +59,11 @@ fn test_chat_de() { }, description: None, invite_link: None, - pinned_message: None + pinned_message: None, }, photo: None, }, - from_str(r#"{"id":0,"type":"channel","username":"channelname"}"#).unwrap() + from_str(r#"{"id":0,"type":"channel","username":"channelname"}"#) + .unwrap() ); } diff --git a/src/core/types/chat_member.rs b/src/core/types/chat_member.rs index e0ddd3f8..1b833ba3 100644 --- a/src/core/types/chat_member.rs +++ b/src/core/types/chat_member.rs @@ -13,8 +13,8 @@ pub struct ChatMember { ///Optional. Administrators only. True, if the bot is allowed to edit /// administrator privileges of that user pub can_be_edited: Option, - ///Optional. Administrators only. True, if the administrator can change the - /// chat title, photo and other settings + ///Optional. Administrators only. True, if the administrator can change + /// the chat title, photo and other settings pub can_change_info: Option, ///Optional. Administrators only. True, if the administrator can post in /// the channel, channels only @@ -25,8 +25,8 @@ pub struct ChatMember { ///Optional. Administrators only. True, if the administrator can delete /// messages of other users pub can_delete_messages: Option, - ///Optional. Administrators only. True, if the administrator can invite new - /// users to the chat + ///Optional. Administrators only. True, if the administrator can invite + /// new users to the chat pub can_invite_users: Option, ///Optional. Administrators only. True, if the administrator can restrict, /// ban or unban chat members @@ -36,17 +36,19 @@ pub struct ChatMember { pub can_pin_messages: Option, ///Optional. Administrators only. True, if the administrator can add new /// administrators with a subset of his own privileges or demote - /// administrators that he has promoted, directly or indirectly (promoted by - /// administrators that were appointed by the user) + /// administrators that he has promoted, directly or indirectly (promoted + /// by administrators that were appointed by the user) pub can_promote_members: Option, ///Optional. Restricted only. True, if the user can send text messages, /// contacts, locations and venues pub can_send_messages: Option, - ///Optional. Restricted only. True, if the user can send audios, documents, - /// photos, videos, video notes and voice notes, implies can_send_messages + ///Optional. Restricted only. True, if the user can send audios, + /// documents, photos, videos, video notes and voice notes, implies + /// can_send_messages pub can_send_media_messages: Option, - ///Optional. Restricted only. True, if the user can send animations, games, - /// stickers and use inline bots, implies can_send_media_messages + ///Optional. Restricted only. True, if the user can send animations, + /// games, stickers and use inline bots, implies + /// can_send_media_messages pub can_send_other_messages: Option, ///Optional. Restricted only. True, if user may add web page previews to /// his messages, implies can_send_media_messages diff --git a/src/core/types/input_file.rs b/src/core/types/input_file.rs index 419c12af..bdade1db 100644 --- a/src/core/types/input_file.rs +++ b/src/core/types/input_file.rs @@ -12,10 +12,14 @@ impl serde::Serialize for InputFile { { match self { InputFile::File(path) => { - // NOTE: file should be actually attached with multipart/form-data + // NOTE: file should be actually attached with + // multipart/form-data serializer.serialize_str( // TODO: remove unwrap (?) - &format!("attach://{}", path.file_name().unwrap().to_string_lossy()), + &format!( + "attach://{}", + path.file_name().unwrap().to_string_lossy() + ), ) } InputFile::Url(url) => serializer.serialize_str(url), diff --git a/src/core/types/input_media.rs b/src/core/types/input_media.rs index ba518320..a47a2655 100644 --- a/src/core/types/input_media.rs +++ b/src/core/types/input_media.rs @@ -15,8 +15,8 @@ pub enum InputMedia { #[serde(skip_serializing_if = "Option::is_none")] caption: Option, /// Send [Markdown] or [HTML], - /// if you want Telegram apps to show [bold, italic, fixed-width text or - /// inline URLs] in the media caption. + /// if you want Telegram apps to show [bold, italic, fixed-width text + /// or inline URLs] in the media caption. /// /// [Markdown]: crate::core::types::ParseMode::Markdown /// [Html]: crate::core::types::ParseMode::Html @@ -31,8 +31,8 @@ pub enum InputMedia { #[serde(skip_serializing_if = "Option::is_none")] /// Thumbnail of the file sent; can be ignored if thumbnail generation /// for the file is supported server-side. - /// The thumbnail should be in JPEG format and less than 200 kB in size. - /// A thumbnail‘s width and height should not exceed 320. + /// The thumbnail should be in JPEG format and less than 200 kB in + /// size. A thumbnail‘s width and height should not exceed 320. /// Ignored if the file is not uploaded using [InputFile::File]. /// /// [InputFile::File]: crate::core::types::InputFile::File @@ -41,8 +41,8 @@ pub enum InputMedia { #[serde(skip_serializing_if = "Option::is_none")] caption: Option, /// Send [Markdown] or [HTML], - /// if you want Telegram apps to show [bold, italic, fixed-width text or - /// inline URLs] in the media caption. + /// if you want Telegram apps to show [bold, italic, fixed-width text + /// or inline URLs] in the media caption. /// /// [Markdown]: crate::core::types::ParseMode::Markdown /// [Html]: crate::core::types::ParseMode::Html @@ -70,8 +70,8 @@ pub enum InputMedia { media: InputFile, /// Thumbnail of the file sent; can be ignored if thumbnail generation /// for the file is supported server-side. - /// The thumbnail should be in JPEG format and less than 200 kB in size. - /// A thumbnail‘s width and height should not exceed 320. + /// The thumbnail should be in JPEG format and less than 200 kB in + /// size. A thumbnail‘s width and height should not exceed 320. /// Ignored if the file is not uploaded using [InputFile::File]. /// /// [InputFile::File]: crate::core::types::InputFile::File @@ -81,8 +81,8 @@ pub enum InputMedia { #[serde(skip_serializing_if = "Option::is_none")] caption: Option, /// Send [Markdown] or [HTML], - /// if you want Telegram apps to show [bold, italic, fixed-width text or - /// inline URLs] in the media caption. + /// if you want Telegram apps to show [bold, italic, fixed-width text + /// or inline URLs] in the media caption. /// /// [Markdown]: crate::core::types::ParseMode::Markdown /// [Html]: crate::core::types::ParseMode::Html @@ -106,8 +106,8 @@ pub enum InputMedia { media: InputFile, /// Thumbnail of the file sent; can be ignored if thumbnail generation /// for the file is supported server-side. - /// The thumbnail should be in JPEG format and less than 200 kB in size. - /// A thumbnail‘s width and height should not exceed 320. + /// The thumbnail should be in JPEG format and less than 200 kB in + /// size. A thumbnail‘s width and height should not exceed 320. /// Ignored if the file is not uploaded using [InputFile::File]. /// /// [InputFile::File]: crate::core::types::InputFile::File @@ -117,8 +117,8 @@ pub enum InputMedia { #[serde(skip_serializing_if = "Option::is_none")] caption: Option, /// Send [Markdown] or [HTML], - /// if you want Telegram apps to show [bold, italic, fixed-width text or - /// inline URLs] in the media caption. + /// if you want Telegram apps to show [bold, italic, fixed-width text + /// or inline URLs] in the media caption. /// /// [Markdown]: crate::core::types::ParseMode::Markdown /// [Html]: crate::core::types::ParseMode::Html @@ -142,8 +142,8 @@ pub enum InputMedia { media: InputFile, /// Thumbnail of the file sent; can be ignored if thumbnail generation /// for the file is supported server-side. - /// The thumbnail should be in JPEG format and less than 200 kB in size. - /// A thumbnail‘s width and height should not exceed 320. + /// The thumbnail should be in JPEG format and less than 200 kB in + /// size. A thumbnail‘s width and height should not exceed 320. /// Ignored if the file is not uploaded using [InputFile::File]. /// /// [InputFile::File]: crate::core::types::InputFile::File @@ -153,8 +153,8 @@ pub enum InputMedia { #[serde(skip_serializing_if = "Option::is_none")] caption: Option, /// Send [Markdown] or [HTML], - /// if you want Telegram apps to show [bold, italic, fixed-width text or - /// inline URLs] in the media caption. + /// if you want Telegram apps to show [bold, italic, fixed-width text + /// or inline URLs] in the media caption. /// /// [Markdown]: crate::core::types::ParseMode::Markdown /// [Html]: crate::core::types::ParseMode::Html diff --git a/src/core/types/input_message_content.rs b/src/core/types/input_message_content.rs index 0cbf50f8..79477263 100644 --- a/src/core/types/input_message_content.rs +++ b/src/core/types/input_message_content.rs @@ -36,7 +36,7 @@ pub enum InputMessageContent { /// Period in seconds for which the location can be updated, should be between 60 and 86400. #[serde(skip_serializing_if = "Option::is_none")] - live_period: Option + live_period: Option, }, /// Represents the content of a venue message to be sent as the result of an inline query. Venue { @@ -86,24 +86,26 @@ mod tests { let text_content = InputMessageContent::Text { message_text: String::from("text"), parse_mode: None, - disable_web_page_preview: None + disable_web_page_preview: None, }; let actual_json = serde_json::to_string(&text_content).unwrap(); assert_eq!(expected_json, actual_json); } + #[test] fn location_serialize() { let expected_json = r#"{"latitude":59.08,"longitude":38.4326}"#; let location_content = InputMessageContent::Location { latitude: 59.08, longitude: 38.4326, - live_period: None + live_period: None, }; let actual_json = serde_json::to_string(&location_content).unwrap(); assert_eq!(expected_json, actual_json); } + #[test] fn venue_serialize() { let expected_json = r#"{"latitude":59.08,"longitude":38.4326,"title":"some title", @@ -114,12 +116,13 @@ mod tests { title: String::from("some title"), address: String::from("some address"), foursquare_id: None, - foursquare_type: None + foursquare_type: None, }; let actual_json = serde_json::to_string(&venue_content).unwrap(); assert_eq!(expected_json, actual_json); } + #[test] fn contact_serialize() { let expected_json = r#"{"phone_number":"+3800000000","first_name":"jhon"}"#; @@ -127,7 +130,7 @@ mod tests { phone_number: String::from("+3800000000"), first_name: String::from("jhon"), last_name: None, - vcard: None + vcard: None, }; let actual_json = serde_json::to_string(&contact_content).unwrap(); diff --git a/src/core/types/location.rs b/src/core/types/location.rs index 5bbb50ab..a01ea2e0 100644 --- a/src/core/types/location.rs +++ b/src/core/types/location.rs @@ -1,4 +1,4 @@ -use serde::{Serialization, Deserialization}; +use serde::{Deserialization, Serialization}; #[derive(Debug, Serialization, Deserialization)] /// This object represents a point on the map. diff --git a/src/core/types/message.rs b/src/core/types/message.rs index be10ac77..112883fa 100644 --- a/src/core/types/message.rs +++ b/src/core/types/message.rs @@ -1,7 +1,7 @@ use crate::core::types::{ - Animation, Audio, Chat, Contact, Document, Game, InlineKeyboardMarkup, Invoice, Location, - MessageEntity, PassportData, PhotoSize, Poll, Sticker, SuccessfulPayment, User, Venue, Video, - VideoNote, Voice, + Animation, Audio, Chat, Contact, Document, Game, InlineKeyboardMarkup, + Invoice, Location, MessageEntity, PassportData, PhotoSize, Poll, Sticker, + SuccessfulPayment, User, Venue, Video, VideoNote, Voice, }; #[derive(Debug, Deserialize, Eq, Hash, PartialEq)] diff --git a/src/core/types/message_entity.rs b/src/core/types/message_entity.rs index 454aefca..79742e90 100644 --- a/src/core/types/message_entity.rs +++ b/src/core/types/message_entity.rs @@ -37,9 +37,11 @@ fn recursive_kind() { url: "ya.ru".into() }, offset: 1, - length: 2 + length: 2, }, - from_str::(r#"{"type":"text_link","url":"ya.ru","offset":1,"length":2}"#) - .unwrap() + from_str::( + r#"{"type":"text_link","url":"ya.ru","offset":1,"length":2}"# + ) + .unwrap() ); } diff --git a/src/core/types/mod.rs b/src/core/types/mod.rs index 8e72aae7..11e39b53 100644 --- a/src/core/types/mod.rs +++ b/src/core/types/mod.rs @@ -1,15 +1,16 @@ use self::not_implemented_types::*; - pub use self::{ - answer_pre_checkout_query::AnswerPreCheckoutQuery, answer_shipping_query::AnswerShippingQuery, - audio::Audio, chat::Chat, chat_member::ChatMember, chat_permissions::ChatPermissions, - chat_photo::ChatPhoto, document::Document, input_file::InputFile, input_media::InputMedia, - invoice::Invoice, label_price::LabeledPrice, message::Message, message_entity::MessageEntity, - order_info::OrderInfo, parse_mode::ParseMode, photo_size::PhotoSize, + answer_pre_checkout_query::AnswerPreCheckoutQuery, + answer_shipping_query::AnswerShippingQuery, audio::Audio, chat::Chat, + chat_member::ChatMember, chat_permissions::ChatPermissions, + chat_photo::ChatPhoto, document::Document, input_file::InputFile, + input_media::InputMedia, invoice::Invoice, label_price::LabeledPrice, + message::Message, message_entity::MessageEntity, order_info::OrderInfo, + parse_mode::ParseMode, photo_size::PhotoSize, pre_checkout_query::PreCheckoutQuery, send_invoice::SendInvoice, shipping_address::ShippingAddress, shipping_option::ShippingOption, - shipping_query::ShippingQuery, sticker::Sticker, successful_payment::SuccessfulPayment, - user::User, video::Video, + shipping_query::ShippingQuery, sticker::Sticker, + successful_payment::SuccessfulPayment, user::User, video::Video, }; mod answer_pre_checkout_query; diff --git a/src/core/types/venue.rs b/src/core/types/venue.rs index 77e02b31..2c1e4c6d 100644 --- a/src/core/types/venue.rs +++ b/src/core/types/venue.rs @@ -1,6 +1,5 @@ use crate::core::types::Location; - #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] pub struct Venue { pub location: Location, @@ -9,5 +8,5 @@ pub struct Venue { #[serde(skip_serializing_if = "Option::is_none")] pub foursquare_id: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub foursquare_type: Option + pub foursquare_type: Option, } \ No newline at end of file diff --git a/src/core/types/voice.rs b/src/core/types/voice.rs index fd69a445..707d5915 100644 --- a/src/core/types/voice.rs +++ b/src/core/types/voice.rs @@ -10,5 +10,5 @@ struct Voice { /// Optional. MIME type of the file as defined by sender pub mime_type: Option, /// Optional. File size - pub file_size: Option + pub file_size: Option, } \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index aa2ac9b2..7425f248 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,5 +3,5 @@ extern crate derive_more; #[macro_use] extern crate serde; +pub mod bot; pub mod core; -pub mod bot; \ No newline at end of file