Derive Clone on plenty of types

This commit is contained in:
Waffle 2019-09-04 21:25:17 +03:00
parent 8ec055b0f9
commit 9b98895a60
52 changed files with 114 additions and 68 deletions

View file

@ -4,7 +4,7 @@ use crate::core::requests::{
};
use crate::core::types::User;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct GetMe<'a> {
info: RequestContext<'a>,
}

View file

@ -45,7 +45,7 @@ pub trait Request<'a> {
pub type RequestFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct RequestContext<'a> {
pub client: &'a Client,
pub token: &'a str,
@ -53,7 +53,7 @@ pub struct RequestContext<'a> {
/// Unique identifier for the target chat or username of the target channel (in
/// the format @channelusername)
#[derive(Debug, Display, Serialize, From, PartialEq, Eq)]
#[derive(Debug, Display, Serialize, From, PartialEq, Eq, Clone)]
pub enum ChatId {
/// chat identifier
#[display(fmt = "{}", _0)]

View file

@ -0,0 +1,46 @@
use crate::core::{
types::{
Message, InputMedia,
},
network::{
request, ResponseResult,
},
requests::{
form_builder::FormBuilder,
ChatId,
Request,
RequestInfo,
RequestFuture,
}
};
/// Use this method to send a group of photos or videos as an album.
#[derive(Debug, TypedBuilder)]
pub struct SendMediaGroup {
info: RequestInfo,
chat_id: ChatId,
media: Vec<InputMedia>,
#[builder(default)]
disable_notification: Option<bool>,
#[builder(default)]
reply_to_message_id: Option<i64>,
}
impl Request for SendMediaGroup {
type ReturnValue = Vec<Message>;
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
Box::pin(async move {
let params = FormBuilder::new()
.add("chat_id", &self.chat_id)
.add("media", &self.media)
.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();
request(&self.info.client, &self.info.token, "sendMediaGroup", Some(params)).await
})
}
}

View file

@ -4,7 +4,7 @@ use crate::core::requests::{
};
use crate::core::{network, types::Message};
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct SendMessage<'a> {
info: RequestContext<'a>,

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone )]
pub struct AnswerPreCheckoutQuery {
pub pre_checkout_query_id: String,
pub ok: bool,

View file

@ -1,6 +1,6 @@
use crate::core::types::ShippingOption;
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct AnswerShippingQuery {
pub shipping_query_id: String,
pub ok: bool,

View file

@ -1,6 +1,6 @@
use crate::core::types::PhotoSize;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Audio {
pub file_id: String,
pub duration: u32,

View file

@ -1,5 +1,5 @@
/// This object represents an incoming callback query from a callback button in an inline keyboard.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct CallbackQuery {
/// Unique identifier for this query
pub id: CallbackQueryId,

View file

@ -1,6 +1,6 @@
use crate::core::types::{ChatPermissions, ChatPhoto, Message};
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Chat {
#[serde(rename = "chat_id")]
pub id: i32,
@ -46,7 +46,7 @@ fn serialize_private_field<S: serde::Serializer>(
ser.serialize_str("private")
}
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
#[serde(rename_all = "snake_case")]
#[serde(untagged)]
pub enum ChatType {
@ -77,7 +77,7 @@ pub enum ChatType {
},
}
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
pub enum NotPrivateChatType {

View file

@ -1,7 +1,7 @@
use crate::core::types::{ChatMemberStatus, User};
/// This object contains information about one member of the chat.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct ChatMember {
/// Information about the user.
pub user: User,

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Serialize)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Serialize, Clone)]
pub struct ChatPermissions {
pub can_send_messages: Option<bool>,
pub can_send_media_messages: Option<bool>,

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Serialize)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Serialize, Clone)]
pub struct ChatPhoto {
pub small_file_id: String,
pub big_file_id: String,

View file

@ -1,6 +1,6 @@
use crate::core::types::user::User;
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
/// Represents a result of an inline query that was chosen by the user and
/// sent to their chat partner.
/// https://core.telegram.org/bots/api#inputtextmessagecontent

View file

@ -1,6 +1,6 @@
use serde::Deserialization;
#[derive(Debug, Deserialization)]
#[derive(Debug, Deserialization, Clone)]
/// This object represents a phone contact.
struct Contact {
/// Contact's phone number

View file

@ -1,6 +1,6 @@
use crate::core::types::PhotoSize;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
pub struct Document {
pub file_id: String,
pub thumb: Option<PhotoSize>,

View file

@ -3,7 +3,7 @@
/// selected the bots message and tapped Reply'). This can be
/// extremely useful if you want to create user-friendly step-by-step
/// interfaces without having to sacrifice privacy mod
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct ForceReply {
pub force_reply: True,
#[serde(skip_serializing_if = "Not::not")]

View file

@ -2,7 +2,7 @@ use serde::Deserialize;
use crate::core::types::MessageEntity;
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
/// This object represents a game. Use BotFather to create and edit games, their short names
/// will act as unique identifiers.
pub struct Game {

View file

@ -2,7 +2,7 @@ use serde::Deserialize;
use crate::core::types::user::User;
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
/// This object represents one row of the high scores table for a game.
pub struct GameHighScore {
/// Position in high score table for the game

View file

@ -1,12 +1,12 @@
/// This object represents one button of an inline keyboard.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct InlineKeyboardButton {
pub text: String,
#[serde(flatten)]
pub kind: InlineKeyboardButtonKind,
}
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize)]
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Clone)]
pub enum InlineKeyboardButtonKind {
#[serde(rename = "url")]
Url(String),

View file

@ -1,5 +1,5 @@
/// This object represents an inline keyboard that appears right next to the message it belongs to.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct InlineKeyboardMarkup {
pub inline_keyboard: Vec<Vec<InlineKeyboardButton>>,
}

View file

@ -1,4 +1,4 @@
#[derive(Debug, Hash, PartialEq, Eq)]
#[derive(Debug, Hash, PartialEq, Eq, Clone)]
pub enum InputFile {
File(std::path::PathBuf),
Url(String),

View file

@ -1,7 +1,7 @@
use crate::core::types::{InputFile, ParseMode};
// TODO: should variants use new-type?
#[derive(Debug, Serialize, PartialEq, Eq)]
#[derive(Debug, Serialize, PartialEq, Eq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
/// This object represents the content of a media message to be sent.

View file

@ -2,7 +2,7 @@ use serde::Serialize;
use crate::core::types::ParseMode;
#[derive(Debug, Serialize)]
#[derive(Debug, Serialize, Clone)]
#[serde(untagged)]
/// This object represents the content of a message to be sent as
/// a result of an inline query.

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct Invoice {
pub title: String,
pub description: String,

View file

@ -1,5 +1,5 @@
/// This object represents one button of the reply keyboard.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct KeyboardButton {
pub text: String,
#[serde(skip_serializing_if = "Not::not")]

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct LabeledPrice {
pub label: String,
pub amount: i64,

View file

@ -1,6 +1,6 @@
use serde::{Deserialization, Serialization};
#[derive(Debug, Serialization, Deserialization)]
#[derive(Debug, Serialization, Deserialization, Clone)]
/// This object represents a point on the map.
struct Location {
/// Longitude as defined by sender

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct LoginUrl {
pub url: String,
#[serde(skip_serializing_if = "Option::is_none")]

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct MaskPosition {
pub point: String,
pub x_shift: f64,

View file

@ -4,7 +4,7 @@ use crate::core::types::{
SuccessfulPayment, User, Venue, Video, VideoNote, Voice,
};
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Message {
#[serde(rename = "message_id")]
pub id: i32,
@ -14,7 +14,7 @@ pub struct Message {
pub type_: MessageType,
}
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
#[serde(rename_all = "snake_case")]
#[serde(untagged)]
pub enum MessageType {}

View file

@ -1,6 +1,6 @@
use crate::core::types::User;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
pub struct MessageEntity {
#[serde(flatten)]
pub kind: MessageEntityKind,
@ -8,7 +8,7 @@ pub struct MessageEntity {
pub length: usize,
}
#[derive(Debug, Deserialize, Eq, Hash, PartialEq)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone)]
#[serde(rename_all = "snake_case")]
#[serde(tag = "type")]
pub enum MessageEntityKind {

View file

@ -1,35 +1,35 @@
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Location;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct InlineKeyboardMarkup;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct PassportData;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Poll;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Animation;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Game;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Contact;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct VideoNote;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Venue;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Voice;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct MaskPosition;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct ChatMemberStatus;

View file

@ -1,6 +1,6 @@
use crate::core::types::ShippingAddress;
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct OrderInfo {
pub name: String,
pub phone_number: String,

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
/// ## Formatting options
/// The Bot API supports basic formatting for messages.
/// You can use **bold** and *italic* text, as well as [inline links](https://example.com) and `pre-formatted code` in

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct PhotoSize {
pub file_id: String,
pub width: i32,

View file

@ -1,6 +1,6 @@
use crate::core::types::{OrderInfo, User};
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct PreCheckoutQuery {
pub id: String,
pub from: User,

View file

@ -1,5 +1,5 @@
/// This object represents a custom keyboard with reply options.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct ReplyKeyboardMarkup {
pub keyboard: Vec<Vec<KeyboardButton>>,
#[serde(skip_serializing_if = "Not::not")]

View file

@ -3,7 +3,7 @@
/// By default, custom keyboards are displayed until a new keyboard is sent
/// by a bot. An exception is made for one-time keyboards that are hidden
/// immediately after the user presses a button (see ReplyKeyboardMarkup).
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct ReplyKeyboardRemove {
pub remove_keyboard: True,
#[serde(skip_serializing_if = "Not::not")]

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct ResponseParameters {
pub migrate_to_chat_id: Option<i64>,
pub retry_after: Option<i64>,

View file

@ -1,6 +1,6 @@
use crate::core::types::{InlineKeyboardMarkup, LabeledPrice};
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct SendInvoice {
pub chat_id: i64,
pub title: String,

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct ShippingAddress {
pub country_code: String,
pub state: String,

View file

@ -1,6 +1,6 @@
use crate::core::types::LabeledPrice;
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct ShippingOption {
pub id: i64,
pub title: String,

View file

@ -1,6 +1,6 @@
use crate::core::types::{ShippingAddress, User};
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct ShippingQuery {
pub id: String,
pub from: User,

View file

@ -1,6 +1,6 @@
use crate::core::types::{MaskPosition, PhotoSize};
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct Sticker {
pub file_id: String,
pub width: u16,

View file

@ -1,6 +1,6 @@
use crate::core::types::Sticker;
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct Sticker {
pub name: String,
pub title: String,

View file

@ -1,6 +1,6 @@
use crate::core::types::OrderInfo;
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct SuccessfulPayment {
pub currency: String,
pub total_amount: i64,

View file

@ -1,4 +1,4 @@
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct User {
pub id: i64,
pub is_bot: bool,

View file

@ -1,6 +1,6 @@
use crate::core::types::Location;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Venue {
pub location: Location,
pub title: String,

View file

@ -1,6 +1,6 @@
use crate::core::types::PhotoSize;
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Serialize, Clone)]
pub struct Video {
pub file_id: String,
pub width: u32,

View file

@ -1,6 +1,6 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
/// This object represents a [video message](https://telegram.org/blog/video-messages-and-telescope)
/// (available in Telegram apps as of v.4.0).
struct VideoNote {

View file

@ -1,6 +1,6 @@
use serde::Deserialize;
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, Clone)]
/// This object represents a voice note.
struct Voice {
/// Identifier for this file

View file

@ -1,7 +1,7 @@
use serde::Deserialize;
/// Contains information about the current status of a webhook.
#[derive(Debug, Deserialize, Hash, PartialEq, Eq)]
#[derive(Debug, Deserialize, Hash, PartialEq, Eq, Clone)]
pub struct WebhookInfo {
/// Webhook URL, may be empty if webhook is not set up
pub url: String,