There are two testing functions from my repo (a public but unfinished project).
The first one (test1
) passes.
And when I move the match
statement from the closure into a function (see test2
and fn append
) , here comes a trouble.
error: captured variable cannot escape `FnMut` closure body
--> tests/extract.rs:149:37
|
147 | let mut paragraphs = buf.split('\n');
| -------------- variable defined here
148 | let output = events.into_iter()
149 | .map(|event| append(event, &mut paragraphs))
| - ^^^^^^^^^^^^^^^^^^^----------^
| | | |
| | | variable captured here
| | returns a reference to a captured variable which escapes t
he closure body
| inferred to be a `FnMut` closure
|
= note: `FnMut` closures only have access to their captured variables while they are executing..
.
= note: ...therefore, they cannot allow references to captured variables to escape
I don't know why test2
fails to compile.
Any explanation is appreciated.