Kon*_*inB 8 traits rust async-await rust-rocket
我正在使用 Rocket 框架,我想在我的处理程序中发出一个异步 HTTP 请求,就像这样
#[get("/")]
async fn handler() -> String {
some_func().await;
"OK".into()
}
Run Code Online (Sandbox Code Playgroud)
结果,我得到了下一个错误
#[get("/")]
async fn handler() -> String {
some_func().await;
"OK".into()
}
Run Code Online (Sandbox Code Playgroud)
我试图编写实现但失败了。有没有办法为 impl Trait 实现 trait?
或者可以指定 async fn 的返回类型,以便我可以返回实现了必要特征的自定义类型?
在 Rocket 0.5.0 发布之前,您将必须使用开发版本进行异步路由。值得注意的是,这也意味着您可以使用稳定的 Rust 进行编译。
在你的 Cargo.toml
rocket = { git = "https://github.com/SergioBenitez/Rocket" }
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket" }
Run Code Online (Sandbox Code Playgroud)
使用开发版本后,您可以完全按照您在问题中所做的来编写异步路由。
请注意,各种 API 可能不同。有关开发版本的文档,请参阅https://api.rocket.rs/master/rocket/index.html。