2017-10-07 7 views
1

Tokioクレートを使ってRustで単純な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
  • トキオ・コア0.1.10
  • トキオ-IO 0.1.3

を使用してい

何私は行方不明ですか?

答えて

5

and_thenの定義を確認:

fn and_then<F, B>(self, f: F) -> AndThen<Self, B, F> 
where 
    F: FnOnce(Self::Item) -> B, 
    B: IntoFuture<Error = Self::Error>, 
    Self: Sized, 

クロージャ(F)が起動閉鎖を(一致エラータイプと未来(B: IntoFuture)に変換することができるいくつかのタイプ(B)を返す必要がありますError = Self::Error)。

クロージャが返品しますか? ()。何故ですか?あなたの行の最後にセミコロン(;)を置いたからです。それを除く。

関連する問題