小编cil*_*lta的帖子

无法推断类型参数的类型 使用 nom 进行解析时出错

nom我用7.1版本进行了测试:

use nom::bytes::complete::tag;

#[test]
fn test() {
    let (s, t) = tag("1")("123").unwrap();
}
Run Code Online (Sandbox Code Playgroud)

跑步cargo test给予

use nom::bytes::complete::tag;

#[test]
fn test() {
    let (s, t) = tag("1")("123").unwrap();
}
Run Code Online (Sandbox Code Playgroud)

它建议我指定tag::<T, Input, Error>()

我该如何处理这个问题?我还没有完全理解为什么会出现这个问题。

我尝试指定一些类型nom

error[E0283]: type annotations needed
  --> src/main.rs:5:18
   |
5  |     let (s, t) = tag("1")("123").unwrap();
   |                  ^^^ cannot infer type for type parameter `Error` declared on the function `tag`
   |
   = note: cannot satisfy `_: ParseError<&str>`
note: required by a bound in `nom::bytes::complete::tag` …
Run Code Online (Sandbox Code Playgroud)

types rust nom

1
推荐指数
1
解决办法
1492
查看次数

标签 统计

nom ×1

rust ×1

types ×1