1
我正嘗試使用Tokio箱子編寫一個簡單的TCP客戶端。我的代碼是非常接近this example減去TLS:當使用TcpConnectionNew時,綁定`():futures :: Future`的特性不被滿足
extern crate futures;
extern crate tokio_core;
extern crate tokio_io;
use futures::Future;
use tokio_core::net::TcpStream;
use tokio_core::reactor::Core;
use tokio_io::io;
fn main() {
let mut core = Core::new().unwrap();
let handle = core.handle();
let connection = TcpStream::connect(&"127.0.0.1:8080".parse().unwrap(), &handle);
let server = connection.and_then(|stream| {
io::write_all(stream, b"hello");
});
core.run(server).unwrap();
}
但是,編譯失敗,出現錯誤:
error[E0277]: the trait bound `(): futures::Future` is not satisfied
--> src/main.rs:16:29
|
16 | let server = connection.and_then(|stream| {
| ^^^^^^^^ the trait `futures::Future` is not implemented for `()`
|
= note: required because of the requirements on the impl of `futures::IntoFuture` for `()`
error[E0277]: the trait bound `(): futures::Future` is not satisfied
--> src/main.rs:20:10
|
20 | core.run(server).unwrap();
| ^^^ the trait `futures::Future` is not implemented for `()`
|
= note: required because of the requirements on the impl of `futures::IntoFuture` for `()`
我覺得很奇怪,因爲根據the documentation應該執行。
我使用
- 鏽1.19.0
- 期貨0.1.16
- TOKIO內核0.1.10
- TOKIO-io的0.1.3
什麼我錯過了嗎?