Open blakehawkins opened 5 years ago
Have you found a workaroud yet? Try to use FnOnce
, but cannot compile:
--> src/parser.rs:45:36
|
37 | pub fn map<U, F>(self, f: F) -> Parser<'a, I, U>
| - captured outer variable
...
45 | (self.method)(input, start).map(|(out, pos)| (f(out), pos))
| ^^^^^^^^^^^^ -
| | |
| | move occurs because `f` has type `F`, which does not implement the `Copy` trait
| | move occurs due to use in closure
| move out of `f` occurs here
@J-F-Liu unfortunately I don't have any elegant solution. I've been copy-pasting this kind of code for each call site where this kind of pattern is needed:
(
indented() |
empty().map(|()| vec![])
).repeat(0..).map(
|lines| lines.into_iter().filter(
|line| line.len() > 0
).fold(
vec![],
|accum, line| accum.into_iter().chain(
line.into_iter().chain(vec![b'\n'].into_iter())
).collect()
)
).map(move |lines| {
*owned_parser*.parse(
&lines
).expect("subparse")
})
I'm trying to generalise the approach found in the
whitespace
example.I think some changes may be needed in pom.
The following function is illegal:
The error is like this:
There is a problem:
map
takesFn
, notFnOnce
, so it's not possible to guarantee idempotence