mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 17:52:12 +01:00
Implement request builders by hand instead of TypedBuilder
This commit is contained in:
parent
fe48ed2730
commit
42c961b595
4 changed files with 66 additions and 18 deletions
|
@ -12,5 +12,4 @@ serde_json = "1.0.39"
|
||||||
serde = {version = "1.0.92", features = ["derive"] }
|
serde = {version = "1.0.92", features = ["derive"] }
|
||||||
lazy_static = "1.3"
|
lazy_static = "1.3"
|
||||||
apply = "0.2.2"
|
apply = "0.2.2"
|
||||||
typed-builder = "0.3.0"
|
|
||||||
derive_more = "0.15.0"
|
derive_more = "0.15.0"
|
|
@ -2,7 +2,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;
|
use crate::core::types::User;
|
||||||
|
|
||||||
#[derive(Debug, Constructor, TypedBuilder)]
|
#[derive(Debug)]
|
||||||
pub struct GetMe<'a> {
|
pub struct GetMe<'a> {
|
||||||
info: RequestInfo<'a>,
|
info: RequestInfo<'a>,
|
||||||
}
|
}
|
||||||
|
@ -16,3 +16,9 @@ impl<'a> Request<'a> for GetMe<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> GetMe<'a> {
|
||||||
|
pub(crate) fn new(info: RequestInfo<'a>) -> Self {
|
||||||
|
GetMe { info }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,23 +2,18 @@ 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};
|
use crate::core::{network, types::Message};
|
||||||
|
|
||||||
#[derive(Debug, TypedBuilder)]
|
#[derive(Debug)]
|
||||||
pub struct SendMessage<'a> {
|
pub struct SendMessage<'a> {
|
||||||
info: RequestInfo<'a>,
|
info: RequestInfo<'a>,
|
||||||
|
|
||||||
chat_id: ChatId,
|
pub chat_id: ChatId,
|
||||||
text: String,
|
pub text: String,
|
||||||
|
|
||||||
#[builder(default)]
|
pub parse_mode: Option<String>, // TODO: ParseMode enum
|
||||||
parse_mode: Option<String>, // TODO: ParseMode enum
|
pub disable_web_page_preview: Option<bool>,
|
||||||
#[builder(default)]
|
pub disable_notification: Option<bool>,
|
||||||
disable_web_page_preview: Option<bool>,
|
pub reply_to_message_id: Option<i64>,
|
||||||
#[builder(default)]
|
pub reply_markup: Option<()>, // TODO: ReplyMarkup enum
|
||||||
disable_notification: Option<bool>,
|
|
||||||
#[builder(default)]
|
|
||||||
reply_to_message_id: Option<i64>,
|
|
||||||
#[builder(default)]
|
|
||||||
reply_markup: Option<()>, // TODO: ReplyMarkup enum
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Request<'a> for SendMessage<'a> {
|
impl<'a> Request<'a> for SendMessage<'a> {
|
||||||
|
@ -48,3 +43,53 @@ impl<'a> Request<'a> for SendMessage<'a> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> SendMessage<'a> {
|
||||||
|
pub(crate) fn new(info: RequestInfo<'a>, chat_id: ChatId, text: String) -> Self {
|
||||||
|
SendMessage {
|
||||||
|
info,
|
||||||
|
chat_id,
|
||||||
|
text,
|
||||||
|
parse_mode: None,
|
||||||
|
disable_web_page_preview: None,
|
||||||
|
disable_notification: None,
|
||||||
|
reply_to_message_id: None,
|
||||||
|
reply_markup: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn chat_id<T: Into<ChatId>>(mut self, val: T) -> Self {
|
||||||
|
self.chat_id = val.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn text<T: Into<String>>(mut self, val: T) -> Self {
|
||||||
|
self.text = val.into();
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_mode<T: Into<String>>(mut self, val: T) -> Self {
|
||||||
|
self.parse_mode = Some(val.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disable_web_page_preview<T: Into<bool>>(mut self, val: T) -> Self {
|
||||||
|
self.disable_web_page_preview = Some(val.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn disable_notification<T: Into<bool>>(mut self, val: T) -> Self {
|
||||||
|
self.disable_notification = Some(val.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reply_to_message_id<T: Into<i64>>(mut self, val: T) -> Self {
|
||||||
|
self.reply_to_message_id = Some(val.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn reply_markup<T: Into<()>>(mut self, val: T) -> Self {
|
||||||
|
self.reply_markup = Some(val.into());
|
||||||
|
self
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,5 @@
|
||||||
extern crate derive_more;
|
extern crate derive_more;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[macro_use]
|
|
||||||
extern crate typed_builder;
|
|
||||||
|
|
||||||
pub mod core;
|
pub mod core;
|
||||||
|
|
Loading…
Reference in a new issue