我正在使用扭曲进行项目。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)