Implement request builders by hand instead of TypedBuilder

This commit is contained in:
Waffle 2019-09-04 11:00:15 +03:00
parent fe48ed2730
commit 42c961b595
4 changed files with 66 additions and 18 deletions

View file

@ -12,5 +12,4 @@ serde_json = "1.0.39"
serde = {version = "1.0.92", features = ["derive"] }
lazy_static = "1.3"
apply = "0.2.2"
typed-builder = "0.3.0"
derive_more = "0.15.0"

View file

@ -2,7 +2,7 @@ use crate::core::network;
use crate::core::requests::{Request, RequestFuture, RequestInfo, ResponseResult};
use crate::core::types::User;
#[derive(Debug, Constructor, TypedBuilder)]
#[derive(Debug)]
pub struct GetMe<'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 }
}
}

View file

@ -2,23 +2,18 @@ use crate::core::requests::form_builder::FormBuilder;
use crate::core::requests::{ChatId, Request, RequestFuture, RequestInfo, ResponseResult};
use crate::core::{network, types::Message};
#[derive(Debug, TypedBuilder)]
#[derive(Debug)]
pub struct SendMessage<'a> {
info: RequestInfo<'a>,
chat_id: ChatId,
text: String,
pub chat_id: ChatId,
pub text: String,
#[builder(default)]
parse_mode: Option<String>, // TODO: ParseMode enum
#[builder(default)]
disable_web_page_preview: Option<bool>,
#[builder(default)]
disable_notification: Option<bool>,
#[builder(default)]
reply_to_message_id: Option<i64>,
#[builder(default)]
reply_markup: Option<()>, // TODO: ReplyMarkup enum
pub parse_mode: Option<String>, // TODO: ParseMode enum
pub disable_web_page_preview: Option<bool>,
pub disable_notification: Option<bool>,
pub reply_to_message_id: Option<i64>,
pub reply_markup: Option<()>, // TODO: ReplyMarkup enum
}
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
}
}

View file

@ -2,7 +2,5 @@
extern crate derive_more;
#[macro_use]
extern crate serde;
#[macro_use]
extern crate typed_builder;
pub mod core;