nom icon indicating copy to clipboard operation
nom copied to clipboard

the trait bound `RangeInclusive<char>: FindToken<_>` is not satisfied

Open drdozer opened this issue 1 year ago • 2 comments

I am not sure if I am using the API incorrectly, or if I have found an edge case that's not yet implemented. I was hoping to be able to write something like this:

    fn parser(s: &str) -> IResult<&str, Self> {
        let (f, file) = nom::character::complete::one_of('a'..='h')(s)?;
        let (r, rank) = nom::character::complete::one_of('1'..='8')(f)?;
        Ok(Square { rank, file })
    }

However, I can't pass in a char range to one_of. I am not quite sure what I should use as an alternative, other than enumerating the characters.

drdozer avatar Nov 11 '24 14:11 drdozer

If you look at the definition of one_of, it takes a FindToken. There is not a FindToken implementation for any of the range types, only different kinds of slice and array types.

I had proposed range types but that was part of a larger effort that stalled out.

epage avatar Nov 11 '24 14:11 epage

OK. I ended up using the predicate test, using the range contains method. But it is a bit verbose, and less declarative. Thanks.

drdozer avatar Nov 14 '24 16:11 drdozer