Hi Jonh, thank you for your reply.
Could you please be more specific on Your code tries to return two that are different
, could you point out which two that I try to return?
I changed client2
mod as following:
use std::time::Duration;
use std::fmt::Write as FmtWrite;
use std::io::Error;
use url::percent_encoding::{percent_encode, QUERY_ENCODE_SET};
use actix_web::{client, Body, Binary, HttpMessage};
use actix_web::http::Method;
use std::collections::HashMap;
use futures::future::{Future, ok, err};
use actix_web::client::{ClientResponse, ClientConnector, Connect};
pub struct MyError<'a>(&'a str);
pub fn get<'a>(url: &'a str, params: &HashMap<&str, &str>) -> impl Future<Item=String, Error=MyError<'a>> {
req(url, params, Method::GET)
}
fn req<'a>(url: &'a str, params: &HashMap<&str, &str>, method: Method) -> impl Future<Item=String, Error=MyError<'a>> {
let mut combined_params = String::with_capacity(1024);
for (key, value) in params {
let value = percent_encode(value.as_bytes(), QUERY_ENCODE_SET).to_string();
let _ = write!(&mut combined_params, "{}={}&", key, value);
}
let mut builder = client::ClientRequest::build();
builder.uri(url);
builder.timeout(Duration::new(6, 0));
if method == Method::POST {
builder.method(Method::POST);
} else {
builder.method(Method::GET);
}
let result = builder
.header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
.body(combined_params);
let c = match result {
Ok(c) => c,
Err(e) => {
println!("request err1 = {}", e);
return err(MyError("Error::InvalidUrlArgument"))
},
};
c.send().then(|r| match r {
Ok(cr) => {
ok("".to_string())
}
Err(err) => {
ok("".to_string())
}
})
}
Still got:
expected struct futures::FutureResult
, found struct futures::Then
note: expected type futures::FutureResult<_, client2::MyError<'_>>
found type futures::Then<actix_web::client::SendRequest, futures::FutureResult<_, _>, [closure@src/client2.rs:51:15: 58:11]>
I checked Future chaining - #2 by vitalyd again, the argument in the lastest closure is Result
, does that determined final returning type?