我编写了以下 nom 解析器代码:
use nom::character::complete::digit1;
use nom::combinator::map_res;
use nom::error::Error;
use nom::sequence::tuple;
use nom::Err;
type E<'a> = Err<Error<&'a str>>;
fn parse_double_int(input: &str) -> Option<(i32, i32)> {
let num = map_res(digit1, |s: &str| s.parse::<i32>());
let mut pair = tuple((num, num));
let res: Result<_, E> = pair(&input.trim());
match res {
Ok((_, (a, b))) => Some((a, b)),
Err(_) => None,
}
}
错误:
error[E0382]: use of moved value: `num`
--> src\lib.rs:11:32
|
10 | let num = map_res(digit1, |s: &str| s.parse::<i32>());
| --- move occurs because `num` has type `impl FnMut<(&str,)>`, which does not implement the `Copy` trait
11 | let mut pair = tuple((num, num));
| --- ^^^ value used here after move
| |
| value moved here
For more information about this error, try `rustc --explain E0382`.
如何重用我在本地定义的解析器?