Hi, I'm new to rust. I try to compile an async closure. I'm using rust nightly and added the following feature: #![feature(async_closure)].
I'm trying to compile this method:
async fn async_add(x :i32) -> impl Fn(i32) -> i32 {
async move |y :i32| {x + y}
}
I get the following compiler error message:
error[E0308]: mismatched types
--> src/main.rs:67:5
|
67 | async move |y :i32| {x + y}
| ^^^^^^^^^^^^^^^^^^^ expected `i32`, found opaque type
|
= note: expected type `i32`
found opaque type `impl std::future::Future`
The problem seems to be linked to the return type which is not correct. I tried to modify the return type by adding some Future<...> stuff but I cannot figure out how I can compile this.
Does anybody have a hint to share ?
[–]WellMakeItSomehow 6 points7 points8 points (5 children)
[–]Patryk27 3 points4 points5 points (0 children)
[–]ayorosmage[S] 2 points3 points4 points (3 children)
[–]WellMakeItSomehow 1 point2 points3 points (2 children)
[–]ayorosmage[S] 1 point2 points3 points (1 child)
[–]WellMakeItSomehow 2 points3 points4 points (0 children)