Hi,
I am running following code:
extern crate futures;
extern crate gcm;
extern crate http;
extern crate reqwest;
#[macro_use]
extern crate serde_derive;
extern crate tokio;
use std::io;
use std::mem;
use futures::{Future, Stream};
use futures::future::{err, ok};
use reqwest::async::{Chunk, Client, Decoder};
use tokio::io::ErrorKind;
#[derive(Deserialize, Debug, Serialize)]
struct Test {
count: u8,
}
fn not_working() -> impl Future<Item=Test, Error=()> {
let result = serde_json::to_string(&Test { count: 9 });
match result {
Err(e) => err(()),
Ok(body) => {
Client::new()
.post("https://hyper.rs")
.body(body)
.send()
.and_then(|mut res| {
println!("{}", res.status());
let x = res.json::<Test>();
x
})
.map_err(|err| ())
.and_then(|ch| ok(ch))
}
}
}
/*fn working() -> impl Future<Item=Test, Error=()> {
let body = serde_json::to_string(&Test { count: 9 }).unwrap();
Client::new()
.post("https://hyper.rs")
.body(body)
.send()
.and_then(|mut res| {
println!("{}", res.status());
let x = res.json::<Test>();
x
})
.map_err(|err| ())
.and_then(|ch| ok(ch))
}*/
fn wrapper() -> impl Future<Item=(), Error=()> {
not_working().and_then(|res| {
println!("Got test {:?}", serde_json::to_string(&res));
ok(())
}).map_err(|err| ())
}
fn main() {
tokio::run(wrapper());
}
This is giving me
error[E0308]: match arms have incompatible types
--> src/main.rs:25:5
|
25 | / match result {
26 | | Err(e) => err(()),
27 | | Ok(body) => {
28 | | Client::new()
... |
39 | | }
40 | | }
| |_____^ expected struct `futures::FutureResult`, found struct `futures::AndThen`
|
= note: expected type `futures::FutureResult<_, _>`
found type `futures::AndThen<futures::MapErr<futures::AndThen<impl futures::Future, impl futures::Future, [closure@src/main.rs:32:27: 36:18]>, [closure@src/main.rs:37:26: 37:34]>, futures::FutureResult<Test, _>, [closure@src/main.rs:38:27: 38:38]>`
note: match arm with an incompatible type
--> src/main.rs:27:21
|
27 | Ok(body) => {
| _____________________^
28 | | Client::new()
29 | | .post("https://hyper.rs")
30 | | .body(body)
... |
38 | | .and_then(|ch| ok(ch))
39 | | }
| |_________^
error: aborting due to 2 previous errors
If I am using working() method in wrapper it is working . Can u pls help understand the reason and solution for not_working() method.
Thanks in advance