Warp has a paradigm like this,
let hi = warp::path("hello")
.and(warp::path::param())
.and(warp::header("user-agent"))
.map(|param: String, agent: String| {
format!("Hello {}, whose agent is {}", param, agent)
});
Those filters provide .map()
which allows you call a closure with the extracted value (output from prior filter).
How do I operate within this paradigm if in the above example I want to do something like this,
.map(async |param: String, agent: String| {
foo(¶m).await?;
format!("Hello {}, whose agent is {}", ¶m, agent)
});
When I use async functions in a closure in the filter's .map
, I get this error,
error[E0708]:
async
non-move
closures with parameters are not currently supported
Is there anyway to make warp
compatible with a library that is already async?
You can use
and_then
:Note that this is not actually an
async
closure, it is a regular closure that returns a future created by anasync
block. See What is the difference between|_| async move {}
andasync move |_| {}
for more information.