nom
nom copied to clipboard
Support `&str` for `number::complete::hex_u32`
Prerequisites
- Rust version : rustc 1.56.0-nightly (6d64f7f69 2021-08-19)
- nom version : 7.0.0
- nom compilation features used: (default)
Test case
use nom::{
IResult,
number::complete::hex_u32,
};
fn hex_u32_on_str() {
let result: IResult<_, _> = hex_u32("a1");
println!("{:?}", result.unwrap())
}
Ideally, I'd like this to compile (or something close).
Currently, we get
error[E0308]: mismatched types
--> src/protocol/parser.rs:17:41
|
17 | let result: IResult<_, _> = hex_u32("a1");
| ^^^^ expected slice `[u8]`, found `str`
|
= note: expected reference `&[u8]`
found reference `&'static str`
help: consider adding a leading `b`
|
17 | let result: IResult<_, _> = hex_u32(b"a1");
| +
Many of the crate::number::complete
methods do support both &[u8] and &str, so it seems viable here.