Compare commits

..

1 Commits

Author SHA1 Message Date
Mahmoud Al-Qudsi d5bfaf7c98 Illustrating alexcrichton/futures-rs/#676 2017-12-09 13:33:08 -06:00
3 changed files with 28 additions and 20 deletions

@ -1,5 +1,4 @@
CARGO = cargo +$(TOOLCHAIN) CARGO = cargo
TOOLCHAIN = nightly
.PHONY: all bench build check clean doc install publish run test update .PHONY: all bench build check clean doc install publish run test update
@ -9,7 +8,7 @@ bench:
@$(CARGO) bench @$(CARGO) bench
build: build:
@env TERM=xterm-256color $(CARGO) build --color=always 2>&1; $(CARGO) build 2> cargo.out 1>/dev/null @env TERM=xterm-256color $(CARGO) build --color=always 2>&1
check: build test check: build test

@ -1,16 +1,24 @@
Compiling futuretest v0.1.0 (file:///mnt/c/Users/Mahmoud/git/futuretest) Compiling futuretest v0.1.0 (file:///mnt/c/Users/Mahmoud/git/futuretest)
error[E0277]: the trait bound `(): futures::Future` is not satisfied error[E0271]: type mismatch resolving `<futures::FutureResult<(), std::string::String> as futures::IntoFuture>::Error == &str`
--> src/main.rs:17:1 --> src/main.rs:12:10
| |
17 | / fn test() -> MapErr<(), ()> { 12 | .and_then(|_|
18 | | future::ok(()) | ^^^^^^^^ expected struct `std::string::String`, found &str
19 | | .map_err(|String| ())
20 | | }
| |_^ the trait `futures::Future` is not implemented for `()`
| |
= note: required by `futures::MapErr` = note: expected type `std::string::String`
found type `&str`
error: aborting due to previous error error[E0599]: no method named `and_then` found for type `futures::AndThen<futures::MapErr<futures::FutureResult<(), ()>, [closure@src/main.rs:11:18: 11:42]>, futures::FutureResult<(), std::string::String>, [closure@src/main.rs:12:19: 15:14]>` in the current scope
--> src/main.rs:17:10
|
17 | .and_then(|_| future::result::<(), String>(Err("another &'static str error".to_owned())))
| ^^^^^^^^
|
= note: the method `and_then` exists but the following trait bounds were not satisfied:
`futures::AndThen<futures::MapErr<futures::FutureResult<(), ()>, [closure@src/main.rs:11:18: 11:42]>, futures::FutureResult<(), std::string::String>, [closure@src/main.rs:12:19: 15:14]> : futures::Future`
`&mut futures::AndThen<futures::MapErr<futures::FutureResult<(), ()>, [closure@src/main.rs:11:18: 11:42]>, futures::FutureResult<(), std::string::String>, [closure@src/main.rs:12:19: 15:14]> : futures::Future`
error: aborting due to 2 previous errors
error: Could not compile `futuretest`. error: Could not compile `futuretest`.

@ -1,5 +1,3 @@
#![feature(conservative_impl_trait)]
extern crate futures; extern crate futures;
extern crate tokio_core; extern crate tokio_core;
use futures::future::{self}; use futures::future::{self};
@ -9,12 +7,15 @@ use tokio_core::reactor::Core;
fn main() { fn main() {
let mut core = Core::new().expect("Failed to initialize tokio_core reactor!"); let mut core = Core::new().expect("Failed to initialize tokio_core reactor!");
let f = test(); let f = future::result::<(),()>(Ok(()))
.map_err(|_| "&'static str error")
.and_then(|_|
future::result(Ok(())
.map_err(|()| "String error".to_owned())
)
)
.and_then(|_| future::result::<(), String>(Err("another &'static str error".to_owned())))
;
core.run(f).unwrap(); core.run(f).unwrap();
} }
fn test() -> MapErr<(), ()> {
future::ok(())
.map_err(|String| ())
}