Asynchronous 在Actix Web中将请求主体转发到响应

Asynchronous 在Actix Web中将请求主体转发到响应,asynchronous,rust,rust-actix,actix-web,Asynchronous,Rust,Rust Actix,Actix Web,我想将Actix Web请求主体转发给响应主体(类似于echo),但它给出了一个类型不匹配的错误 use actix_web::*; use futures::future::ok; use futures::Future; fn show_request( request: &actix_web::HttpRequest ) -> Box<Future<Item=HttpResponse, Error=Error>> { request

我想将Actix Web请求主体转发给响应主体(类似于echo),但它给出了一个类型不匹配的错误

use actix_web::*;
use futures::future::ok;
use futures::Future;

fn show_request(
    request: &actix_web::HttpRequest
) -> Box<Future<Item=HttpResponse, Error=Error>> {
    request
        .body()
        .from_err::<actix_web::error::PayloadError>()
        .map(move |f| {
            Box::new(ok(actix_web::HttpResponse::Ok()
                .content_type("text/plain")
                .body(f)))
        })
}

pub fn index(scope: actix_web::Scope<()>) -> actix_web::Scope<()> {
    scope.handler("", |req: &actix_web::HttpRequest| {
        show_request(req)
    })
}

fn main() {
    actix_web::server::new(|| {
        vec![
            actix_web::App::new()
                .scope("", index)
                .boxed(),

        ]
    }).bind("127.0.0.1:8000")
        .expect("Can not bind to port 8000")
        .run();
}

错误:

错误[E0308]:类型不匹配
-->src/项目资源:50:2
|
49 |)->框{
|------------------------------------应为'std::boxed::Box`
找到类型“futures::Map”`

为什么会发生此错误,我如何修复它?

您试图返回一个
未来
而不使用
ing,您是
映射
的闭包中调用响应,而不是预期的
未来
。使用
未来::确定
是不必要的,因为您的
请求。正文
已经被删除未来

fn show_request(
    request: &actix_web::HttpRequest,
) -> Box<Future<Item = HttpResponse, Error = Error>> {
    Box::new(request.body().map_err(|e| e.into()).map(move |f| {
        actix_web::HttpResponse::Ok()
            .content_type("text/plain")
            .body(f)
    }))
}
fn显示请求(
请求:&actix_web::HttpRequest,
)->盒子{
框::新建(request.body().map_err(|e | e.into()).map(move | f |{
actix_web::HttpResponse::Ok()
.内容类型(“文本/普通”)
.机构(f)
}))
}
fn show_request(
    request: &actix_web::HttpRequest,
) -> Box<Future<Item = HttpResponse, Error = Error>> {
    Box::new(request.body().map_err(|e| e.into()).map(move |f| {
        actix_web::HttpResponse::Ok()
            .content_type("text/plain")
            .body(f)
    }))
}