小编Pet*_*ght的帖子

我应该如何使用依赖项的依赖项?

我正在使用扭曲进行项目。Warp 包含字节货物作为依赖项,我想使用传递到回调中的字节结构。这是一个例子:

use warp::Filter;

fn process(data: bytes::Bytes) -> impl warp::reply::Reply {
    println!("{:?}", data);
    "processed!"
}

#[tokio::main]
async fn main() {
    let process = warp::path("process")
        .and(warp::post())
        .and(warp::body::bytes())
        .map(process);

    warp::serve(process)
        .run(([127, 0, 0, 1], 3030))
        .await;
}
Run Code Online (Sandbox Code Playgroud)

这是我的 Cargo.toml 中的依赖项:

[dependencies]
bytes = "*"
tokio = { version = "0.2", features = ["full"] }
warp = "0.2"
Run Code Online (Sandbox Code Playgroud)

这个设置给了我这个错误:

error[E0631]: type mismatch in function arguments
  --> src/main.rs:13:14
   |
3  | fn process(data: bytes::Bytes) -> impl warp::reply::Reply {
   | --------------------------------------------------------- found signature of `fn(bytes::bytes::Bytes) …
Run Code Online (Sandbox Code Playgroud)

rust rust-cargo

6
推荐指数
1
解决办法
1053
查看次数

标签 统计

rust ×1

rust-cargo ×1