Fixed problems with borrow checker in core/requests

This commit is contained in:
Mr-Andersen 2019-09-03 14:15:54 +03:00
parent 5e57abf676
commit 8511aeb609
6 changed files with 16 additions and 20 deletions

View file

@ -32,16 +32,14 @@ impl FormBuilder {
where where
T: Serialize, T: Serialize,
{ {
Self { match value {
form: value.map_or_else( None => Self { form: self.form },
|| self.form, Some(value) => Self {
|value| { form: self.form.text(
self.form.text(
name.to_owned(), 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"),
) )
}, }
),
} }
} }

View file

@ -18,7 +18,7 @@ impl Request for GetMe {
type ReturnValue = User; type ReturnValue = User;
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> { fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
Box::new(async { Box::new(async move {
request(&self.info.client, &self.info.token, "getMe", None).await request(&self.info.client, &self.info.token, "getMe", None).await
}) })
} }

View file

@ -22,9 +22,9 @@ pub type RequestFuture<T> = Box<dyn Future<Output = T>>;
// todo: better name? // todo: better name?
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct RequestInfo { pub struct RequestInfo {
pub(crate) client: Client, pub client: Client,
pub(crate) token: String, pub token: String,
} }
/// Unique identifier for the target chat or username of the target channel (in /// Unique identifier for the target chat or username of the target channel (in

View file

@ -37,7 +37,7 @@ impl Request for SendMessage {
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> { fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
Box::new(async { Box::new(async move {
let params = FormBuilder::new() let params = FormBuilder::new()
.add("chat_id", &self.chat_id) .add("chat_id", &self.chat_id)
.add("text", &self.text) .add("text", &self.text)

View file

@ -12,15 +12,15 @@ pub struct MessageEntity {
#[derive(Deserialize, Debug, PartialEq, Hash, Eq)] #[derive(Deserialize, Debug, PartialEq, Hash, Eq)]
#[serde(rename_all = "snake_case")] #[serde(rename_all = "snake_case")]
#[serde(tag = "type")] #[serde(tag = "type")]
enum MessageEntityKind { pub enum MessageEntityKind {
Mention, Hashtag, Cashtag, BotCommand, Url, Email, PhoneNumber, Mention, Hashtag, Cashtag, BotCommand, Url, Email, PhoneNumber,
Bold, Italic, Code, Pre, Bold, Italic, Code, Pre,
TextLink { url: String }, TextLink { url: String },
TextMention { user: User } TextMention { user: User }
} }
#[cfg(test)] #[test]
fn test() { fn recursive_kind() {
use serde_json::from_str; use serde_json::from_str;
assert_eq!( assert_eq!(

View file

@ -1,5 +1,3 @@
#![feature(async_await)]
#[macro_use] #[macro_use]
extern crate derive_more; extern crate derive_more;
#[macro_use] #[macro_use]