I got compile error when I tried to mutate variable.
The error is
⣿
Errors
Exited with status 101
Standard Error
Compiling playground v0.0.1 (/playground)
error: async closure does not implement `FnMut` because it captures state from its environment
--> src/main.rs:51:42
|
51 | let mut stream = pin!(StreamObj::new(async || {
| -------------- ^^^^^^^^
| |
| required by a bound introduced by this call
|
note: required by a bound in `StreamObj::<F, FUT, O>::new`
--> src/main.rs:14:8
|
14 | F: FnMut() -> FUT,
| ^^^^^^^^^^^^^^ required by this bound in `StreamObj::<F, FUT, O>::new`
...
17 | pub fn new(fetcher: F) -> Self {
| --- required by a bound in this associated function
error: could not compile `playground` (bin "playground") due to 1 previous error
Standard Output
If I don't mutate variable then the error disappear.
My questions:
- Is there a better way to construct Stream that fetch data using async library beside splitting generic from
AsyncFnMut() -> O
into two genericF
andFut
in order for me to keep future return by such library ? - Is there a way to force async closure to be FnMut ? It seem like the error message is telling me that this closure is not FnMut or AsyncFnMut. Did I misunderstood the compile error message ?
My experimental playground: