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
T: Serialize,
{
Self {
form: value.map_or_else(
|| self.form,
|value| {
self.form.text(
name.to_owned(),
serde_json::to_string(value).expect("serde_json::to_string failed"),
)
},
),
match value {
None => Self { form: self.form },
Some(value) => Self {
form: self.form.text(
name.to_owned(),
serde_json::to_string(value).expect("serde_json::to_string failed"),
)
}
}
}

View file

@ -18,7 +18,7 @@ impl Request for GetMe {
type ReturnValue = User;
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>> {
Box::new(async {
Box::new(async move {
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?
#[derive(Debug)]
pub(crate) struct RequestInfo {
pub(crate) client: Client,
pub(crate) token: String,
pub struct RequestInfo {
pub client: Client,
pub token: String,
}
/// 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>> {
Box::new(async {
Box::new(async move {
let params = FormBuilder::new()
.add("chat_id", &self.chat_id)
.add("text", &self.text)

View file

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

View file

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