Pin RequestFuture

This commit is contained in:
Waffle 2019-09-03 20:23:52 +03:00
parent 9f8396f752
commit f100bdc7ed
3 changed files with 10 additions and 3 deletions

View file

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

View file

@ -1,4 +1,5 @@
use std::future::Future;
use std::pin::Pin;
use reqwest::r#async::Client;
use reqwest::StatusCode;
@ -42,7 +43,9 @@ pub trait Request {
fn send(self) -> RequestFuture<ResponseResult<Self::ReturnValue>>;
}
pub type RequestFuture<T> = Box<dyn Future<Output = T>>;
pub type RequestFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
// todo: better name?
#[derive(Debug)]
@ -65,3 +68,7 @@ pub enum ChatId {
pub mod get_me;
pub mod send_message;
fn a() {
use futures;
}

View file

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