Create Request::Output

This commit is contained in:
Temirkhan Myrzamadi 2020-01-03 17:41:42 +06:00
parent 69e70b1d0e
commit 2dcfc824f6
66 changed files with 200 additions and 67 deletions

View file

@ -36,7 +36,9 @@ pub struct AddStickerToSet<'a> {
}
#[async_trait::async_trait]
impl Request<True> for AddStickerToSet<'_> {
impl Request for AddStickerToSet<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_multipart(
self.bot.client(),

View file

@ -41,7 +41,9 @@ pub struct AnswerCallbackQuery<'a> {
}
#[async_trait::async_trait]
impl Request<True> for AnswerCallbackQuery<'_> {
impl Request for AnswerCallbackQuery<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -50,7 +50,9 @@ pub struct AnswerInlineQuery<'a> {
}
#[async_trait::async_trait]
impl Request<True> for AnswerInlineQuery<'_> {
impl Request for AnswerInlineQuery<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -34,7 +34,9 @@ pub struct AnswerPreCheckoutQuery<'a> {
}
#[async_trait::async_trait]
impl Request<True> for AnswerPreCheckoutQuery<'_> {
impl Request for AnswerPreCheckoutQuery<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -34,7 +34,9 @@ pub struct AnswerShippingQuery<'a> {
}
#[async_trait::async_trait]
impl Request<True> for AnswerShippingQuery<'_> {
impl Request for AnswerShippingQuery<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -42,7 +42,9 @@ pub struct CreateNewStickerSet<'a> {
}
#[async_trait::async_trait]
impl Request<True> for CreateNewStickerSet<'_> {
impl Request for CreateNewStickerSet<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_multipart(
self.bot.client(),

View file

@ -22,7 +22,9 @@ pub struct DeleteChatPhoto<'a> {
}
#[async_trait::async_trait]
impl Request<True> for DeleteChatPhoto<'_> {
impl Request for DeleteChatPhoto<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -24,7 +24,9 @@ pub struct DeleteChatStickerSet<'a> {
}
#[async_trait::async_trait]
impl Request<True> for DeleteChatStickerSet<'_> {
impl Request for DeleteChatStickerSet<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -30,7 +30,9 @@ pub struct DeleteMessage<'a> {
}
#[async_trait::async_trait]
impl Request<True> for DeleteMessage<'_> {
impl Request for DeleteMessage<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -20,7 +20,9 @@ pub struct DeleteStickerFromSet<'a> {
}
#[async_trait::async_trait]
impl Request<True> for DeleteStickerFromSet<'_> {
impl Request for DeleteStickerFromSet<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -17,7 +17,9 @@ pub struct DeleteWebhook<'a> {
}
#[async_trait::async_trait]
impl Request<True> for DeleteWebhook<'_> {
impl Request for DeleteWebhook<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -29,7 +29,9 @@ pub struct EditMessageCaption<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageCaption<'_> {
impl Request for EditMessageCaption<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -29,7 +29,9 @@ pub struct EditMessageLiveLocation<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageLiveLocation<'_> {
impl Request for EditMessageLiveLocation<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -30,7 +30,9 @@ pub struct EditMessageMedia<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageMedia<'_> {
impl Request for EditMessageMedia<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
let mut params = FormBuilder::new();

View file

@ -24,7 +24,9 @@ pub struct EditMessageReplyMarkup<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageReplyMarkup<'_> {
impl Request for EditMessageReplyMarkup<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -31,7 +31,9 @@ pub struct EditMessageText<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for EditMessageText<'_> {
impl Request for EditMessageText<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -29,7 +29,9 @@ pub struct ExportChatInviteLink<'a> {
}
#[async_trait::async_trait]
impl Request<String> for ExportChatInviteLink<'_> {
impl Request for ExportChatInviteLink<'_> {
type Output = String;
async fn send(&self) -> ResponseResult<String> {
network::request_json(
self.bot.client(),

View file

@ -29,7 +29,9 @@ pub struct ForwardMessage<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for ForwardMessage<'_> {
impl Request for ForwardMessage<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -22,7 +22,9 @@ pub struct GetChat<'a> {
}
#[async_trait::async_trait]
impl Request<Chat> for GetChat<'_> {
impl Request for GetChat<'_> {
type Output = Chat;
async fn send(&self) -> ResponseResult<Chat> {
network::request_json(
self.bot.client(),

View file

@ -24,7 +24,9 @@ pub struct GetChatAdministrators<'a> {
}
#[async_trait::async_trait]
impl Request<Vec<ChatMember>> for GetChatAdministrators<'_> {
impl Request for GetChatAdministrators<'_> {
type Output = Vec<ChatMember>;
async fn send(&self) -> ResponseResult<Vec<ChatMember>> {
network::request_json(
self.bot.client(),

View file

@ -23,7 +23,9 @@ pub struct GetChatMember<'a> {
}
#[async_trait::async_trait]
impl Request<ChatMember> for GetChatMember<'_> {
impl Request for GetChatMember<'_> {
type Output = ChatMember;
async fn send(&self) -> ResponseResult<ChatMember> {
network::request_json(
self.bot.client(),

View file

@ -21,7 +21,9 @@ pub struct GetChatMembersCount<'a> {
}
#[async_trait::async_trait]
impl Request<i32> for GetChatMembersCount<'_> {
impl Request for GetChatMembersCount<'_> {
type Output = i32;
async fn send(&self) -> ResponseResult<i32> {
network::request_json(
self.bot.client(),

View file

@ -37,7 +37,9 @@ pub struct GetFile<'a> {
}
#[async_trait::async_trait]
impl Request<File> for GetFile<'_> {
impl Request for GetFile<'_> {
type Output = File;
async fn send(&self) -> ResponseResult<File> {
network::request_json(
self.bot.client(),

View file

@ -27,7 +27,9 @@ pub struct GetGameHighScores<'a> {
}
#[async_trait::async_trait]
impl Request<Vec<GameHighScore>> for GetGameHighScores<'_> {
impl Request for GetGameHighScores<'_> {
type Output = Vec<GameHighScore>;
async fn send(&self) -> ResponseResult<Vec<GameHighScore>> {
network::request_json(
self.bot.client(),

View file

@ -17,7 +17,9 @@ pub struct GetMe<'a> {
}
#[async_trait::async_trait]
impl Request<User> for GetMe<'_> {
impl Request for GetMe<'_> {
type Output = User;
#[allow(clippy::trivially_copy_pass_by_ref)]
async fn send(&self) -> ResponseResult<User> {
network::request_json(

View file

@ -20,7 +20,9 @@ pub struct GetStickerSet<'a> {
}
#[async_trait::async_trait]
impl Request<StickerSet> for GetStickerSet<'_> {
impl Request for GetStickerSet<'_> {
type Output = StickerSet;
async fn send(&self) -> ResponseResult<StickerSet> {
network::request_json(
self.bot.client(),

View file

@ -66,7 +66,9 @@ pub struct GetUpdates<'a> {
}
#[async_trait::async_trait]
impl Request<Vec<Update>> for GetUpdates<'_> {
impl Request for GetUpdates<'_> {
type Output = Vec<Update>;
async fn send(&self) -> ResponseResult<Vec<Update>> {
network::request_json(
self.bot.client(),

View file

@ -26,7 +26,9 @@ pub struct GetUserProfilePhotos<'a> {
}
#[async_trait::async_trait]
impl Request<UserProfilePhotos> for GetUserProfilePhotos<'_> {
impl Request for GetUserProfilePhotos<'_> {
type Output = UserProfilePhotos;
async fn send(&self) -> ResponseResult<UserProfilePhotos> {
network::request_json(
self.bot.client(),

View file

@ -17,7 +17,9 @@ pub struct GetWebhookInfo<'a> {
}
#[async_trait::async_trait]
impl Request<WebhookInfo> for GetWebhookInfo<'_> {
impl Request for GetWebhookInfo<'_> {
type Output = WebhookInfo;
async fn send(&self) -> ResponseResult<WebhookInfo> {
network::request_json(
self.bot.client(),

View file

@ -30,7 +30,9 @@ pub struct KickChatMember<'a> {
}
#[async_trait::async_trait]
impl Request<True> for KickChatMember<'_> {
impl Request for KickChatMember<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -21,7 +21,9 @@ pub struct LeaveChat<'a> {
}
#[async_trait::async_trait]
impl Request<True> for LeaveChat<'_> {
impl Request for LeaveChat<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -29,7 +29,9 @@ pub struct PinChatMessage<'a> {
}
#[async_trait::async_trait]
impl Request<True> for PinChatMessage<'_> {
impl Request for PinChatMessage<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -46,7 +46,9 @@ pub struct PromoteChatMember<'a> {
}
#[async_trait::async_trait]
impl Request<True> for PromoteChatMember<'_> {
impl Request for PromoteChatMember<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -31,7 +31,9 @@ pub struct RestrictChatMember<'a> {
}
#[async_trait::async_trait]
impl Request<True> for RestrictChatMember<'_> {
impl Request for RestrictChatMember<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -62,7 +62,9 @@ pub struct SendAnimation<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendAnimation<'_> {
impl Request for SendAnimation<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_multipart(
self.bot.client(),

View file

@ -58,7 +58,9 @@ pub struct SendAudio<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendAudio<'_> {
impl Request for SendAudio<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_multipart(
self.bot.client(),

View file

@ -68,7 +68,9 @@ pub enum SendChatActionKind {
}
#[async_trait::async_trait]
impl Request<True> for SendChatAction<'_> {
impl Request for SendChatAction<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -38,7 +38,9 @@ pub struct SendContact<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendContact<'_> {
impl Request for SendContact<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -51,7 +51,9 @@ pub struct SendDocument<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendDocument<'_> {
impl Request for SendDocument<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_multipart(
self.bot.client(),

View file

@ -31,7 +31,9 @@ pub struct SendGame<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendGame<'_> {
impl Request for SendGame<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -75,7 +75,9 @@ pub struct SendInvoice<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendInvoice<'_> {
impl Request for SendInvoice<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -37,7 +37,9 @@ pub struct SendLocation<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendLocation<'_> {
impl Request for SendLocation<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -29,7 +29,9 @@ pub struct SendMediaGroup<'a> {
}
#[async_trait::async_trait]
impl Request<Vec<Message>> for SendMediaGroup<'_> {
impl Request for SendMediaGroup<'_> {
type Output = Vec<Message>;
async fn send(&self) -> ResponseResult<Vec<Message>> {
network::request_multipart(
self.bot.client(),

View file

@ -45,7 +45,9 @@ pub struct SendMessage<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendMessage<'_> {
impl Request for SendMessage<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -40,7 +40,9 @@ pub struct SendPhoto<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendPhoto<'_> {
impl Request for SendPhoto<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_multipart(
self.bot.client(),

View file

@ -35,7 +35,9 @@ pub struct SendPoll<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendPoll<'_> {
impl Request for SendPoll<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -35,7 +35,9 @@ pub struct SendSticker<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendSticker<'_> {
impl Request for SendSticker<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_multipart(
self.bot.client(),

View file

@ -44,7 +44,9 @@ pub struct SendVenue<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendVenue<'_> {
impl Request for SendVenue<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -60,7 +60,9 @@ pub struct SendVideo<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendVideo<'_> {
impl Request for SendVideo<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_multipart(
self.bot.client(),

View file

@ -49,7 +49,9 @@ pub struct SendVideoNote<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendVideoNote<'_> {
impl Request for SendVideoNote<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_multipart(
self.bot.client(),

View file

@ -46,7 +46,9 @@ pub struct SendVoice<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SendVoice<'_> {
impl Request for SendVoice<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_multipart(
self.bot.client(),

View file

@ -28,7 +28,9 @@ pub struct SetChatAdministratorCustomTitle<'a> {
}
#[async_trait::async_trait]
impl Request<True> for SetChatAdministratorCustomTitle<'_> {
impl Request for SetChatAdministratorCustomTitle<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -24,7 +24,9 @@ pub struct SetChatDescription<'a> {
}
#[async_trait::async_trait]
impl Request<True> for SetChatDescription<'_> {
impl Request for SetChatDescription<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -24,7 +24,9 @@ pub struct SetChatPermissions<'a> {
}
#[async_trait::async_trait]
impl Request<True> for SetChatPermissions<'_> {
impl Request for SetChatPermissions<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -25,7 +25,9 @@ pub struct SetChatPhoto<'a> {
}
#[async_trait::async_trait]
impl Request<True> for SetChatPhoto<'_> {
impl Request for SetChatPhoto<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -26,7 +26,9 @@ pub struct SetChatStickerSet<'a> {
}
#[async_trait::async_trait]
impl Request<True> for SetChatStickerSet<'_> {
impl Request for SetChatStickerSet<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -24,7 +24,9 @@ pub struct SetChatTitle<'a> {
}
#[async_trait::async_trait]
impl Request<True> for SetChatTitle<'_> {
impl Request for SetChatTitle<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -33,7 +33,9 @@ pub struct SetGameScore<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for SetGameScore<'_> {
impl Request for SetGameScore<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -22,7 +22,9 @@ pub struct SetStickerPositionInSet<'a> {
}
#[async_trait::async_trait]
impl Request<True> for SetStickerPositionInSet<'_> {
impl Request for SetStickerPositionInSet<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -49,7 +49,9 @@ pub struct SetWebhook<'a> {
}
#[async_trait::async_trait]
impl Request<True> for SetWebhook<'_> {
impl Request for SetWebhook<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -24,7 +24,9 @@ pub struct StopMessageLiveLocation<'a> {
}
#[async_trait::async_trait]
impl Request<Message> for StopMessageLiveLocation<'_> {
impl Request for StopMessageLiveLocation<'_> {
type Output = Message;
async fn send(&self) -> ResponseResult<Message> {
network::request_json(
self.bot.client(),

View file

@ -25,7 +25,9 @@ pub struct StopPoll<'a> {
}
#[async_trait::async_trait]
impl Request<Poll> for StopPoll<'_> {
impl Request for StopPoll<'_> {
type Output = Poll;
async fn send(&self) -> ResponseResult<Poll> {
network::request_json(
self.bot.client(),

View file

@ -25,7 +25,9 @@ pub struct UnbanChatMember<'a> {
}
#[async_trait::async_trait]
impl Request<True> for UnbanChatMember<'_> {
impl Request for UnbanChatMember<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -23,7 +23,9 @@ pub struct UnpinChatMessage<'a> {
}
#[async_trait::async_trait]
impl Request<True> for UnpinChatMessage<'_> {
impl Request for UnpinChatMessage<'_> {
type Output = True;
async fn send(&self) -> ResponseResult<True> {
network::request_json(
self.bot.client(),

View file

@ -24,7 +24,9 @@ pub struct UploadStickerFile<'a> {
png_sticker: InputFile,
}
#[async_trait::async_trait]
impl Request<File> for UploadStickerFile<'_> {
impl Request for UploadStickerFile<'_> {
type Output = File;
async fn send(&self) -> ResponseResult<File> {
network::request_json(
self.bot.client(),

View file

@ -11,7 +11,10 @@ pub type ResponseResult<T> = Result<T, crate::RequestError>;
/// Designates an API request.
#[async_trait::async_trait]
pub trait Request<T> {
pub trait Request {
/// A data structure returned if success.
type Output;
/// Asynchronously sends this request to Telegram and returns the result.
async fn send(&self) -> ResponseResult<T>;
async fn send(&self) -> ResponseResult<Self::Output>;
}