I am getting error message from compiler which I don't understand.
Full error message is:
⣿
Errors
Exited with status 101
Standard Error
Compiling playground v0.0.1 (/playground)
error[E0507]: cannot move out of `value` which is behind a mutable reference
--> src/main.rs:2:5
|
2 | async move || {
| ^^^^^^^^^^^^^ `value` is moved here
3 | value
| -----
| |
| variable moved due to use in coroutine
| move occurs because `value` has type `String`, which does not implement the `Copy` trait
For more information about this error, try `rustc --explain E0507`.
error: could not compile `playground` (bin "playground") due to 1 previous error
You have asked that the closure implement AsyncFnMut, which means, among other things, that it is callable more than once (as opposed to AsyncFnOnce). But in the closure, you have value,
async move || {
value
}
which means that when the closure is called, it gives away its value — the String will be moved to its caller. Therefore, it no longer has any value. Therefore, it cannot be called again because it has nothing to give away a second time.
To fix this, either change the contents of the closure to value.clone(), or replace AsyncFnMut with AsyncFnOnce, depending on what your goal is.
There is a brief mention “this also applies to FnMut”, but indeed there are not any details or examples. You can file a documentation issue with your thoughts on what would make a good addition to the documentation there. Feel free to use my text if it helps (though I don't think it will particularly; I wrote it for your situation in particular).