Actix 请求错误,特征 `std::future::Future` 没有为 `Request<()>` 实现

时间:2021-05-20 05:17:27

标签: api asynchronous rust actix-web rust-actix

我对 Rust 非常陌生,正在尝试向内部 API 发出发布请求。我收到错误:

       match request.await {
             ^^^^^^^^^^^^^ `Request<()>` is not a future
   
   = help: the trait `std::future::Future` is not implemented for `Request<()>`
   = note: required by `poll`

在我的 lib.rs 中,我有:


pub async fn make_request(path: &str) -> Request<()>{
    let request = Request::post(format!("http://localhost:8000/{}", path)) 
        .body(())
        .unwrap();

     match request.await {
         Ok(res) => println!("Response: {}", res.status()),
         Err(err) => println!("Error: {}", err),
    }
}

在具有以下代码的模块中调用:

pub async fn get_names(req_body: String) -> impl Responder { 
    HttpResponse::Ok().body(req_body);
    make_request("/names");
}

我理解“未来”等同于 JavaScript 承诺,所以我认为 match 语句会起作用,所以我尝试在请求中添加 .await() 但不确定是否必须创建一个结构来保存我将在 make_request 中实施的响应?同样,我真的是 Rust 的新手,任何帮助将不胜感激。谢谢!

0 个答案:

没有答案