我正在尝试学习使用 nom (5.0.1) 并希望获取两个标签之间的字符串:
use nom::{
bytes::complete::{tag_no_case, take_while},
character::{is_alphanumeric},
error::{ParseError},
sequence::{delimited},
IResult,
};
fn root<'a, E: ParseError<&'a str>>(i: &'a str) -> IResult<&'a str, &str, E> {
delimited(
tag_no_case("START;"),
take_while(is_alphanumeric),
tag_no_case("END;"),
)(i)
}
但这给了我错误
error[E0271]: type mismatch resolving `<&str as nom::InputTakeAtPosition>::Item == u8`
--> src/main.rs:128:9
|
128 | take_while(is_alphanumeric),
| ^^^^^^^^^^^ expected char, found u8
我在这里做错了什么?我对 Rust 还很陌生,而且是 nom 的初学者,所以我希望它最终会变得非常明显:)