0

ハイパーフレームワークでリバースプロキシを書いてRustを学びたいです。私の完全なプロジェクトは GitHub にありますドキュメントで説明されているように、リスナーの開始に行き詰まっています:

extern crate hyper;

use hyper::Client;
use hyper::server::{Server, Request, Response};
use std::io::Read;

fn pipe_through(req: Request, res: Response) {
    let client = Client::new();
    // Why does the response have to be mutable here? We never need to modify it, so we should be
    // able to remove "mut"?
    let mut response = client.get("http://drupal-8.localhost/").send().unwrap();
    // Print out all the headers first.
    for header in response.headers.iter() {
        println!("{}", header);
    }
    // Now the body. This is ugly, why do I have to create an intermediary string variable? I want
    // to push the response directly to stdout.
    let mut body = String::new();
    response.read_to_string(&mut body).unwrap();
    print!("{}", body);
}

Server::http("127.0.0.1:9090").unwrap().handle(pipe_through).unwrap();

これは機能せず、次のコンパイル エラーで失敗します。

error: expected one of `!` or `::`, found `(`
  --> src/main.rs:23:13
   |
23 | Server::http("127.0.0.1:9090").unwrap().handle(pipe_through).unwrap();
   |             ^

私の呼び出しがhttp()正しくないのはなぜですか? ドキュメントに示されているように、新しいサーバーを作成するべきではありませんか?

4

1 に答える 1