我正在使用nom在rust中构建解析器,并且在遇到E0282错误时遇到很多麻烦。我有这个枚举:
#[derive(Debug, PartialEq, Clone)]
enum Direction { N, E, S, W }
我正在使用此解析器进行构建:
named!(direction_parser<&[u8], Direction>,
map_res!(alt!(tag_no_case!("N") | tag_no_case!("E") |
tag_no_case!("S") | tag_no_case!("W")),
|result: &[u8]|
match str::from_utf8(result)? {
"n" | "N" => Ok(Direction::N),
"e" | "E" => Ok(Direction::E),
"s" | "S" => Ok(Direction::S),
"w" | "W" => Ok(Direction::W)
}));
但是我一直收到此错误:
error[E0282]: type annotations needed
--> src/lib.rs:96:1
|
96 | / named!(direction_parser<&[u8], Direction>,
97 | | map_res!(alt!(tag_no_case!("N") | tag_no_case!("E") |
98 | | tag_no_case!("S") | tag_no_case!("W")),
99 | | |result: &[u8]|
... |
104 | | "w" | "W" => Ok(Direction::W)
105 | | }));
| |____________________^ cannot infer type for `E2`
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
我使用了宏回溯标志,但最终变得更加混乱。我需要在哪里添加类型注释?