winnow-rs / winnow

Making parsing a breeze
https://docs.rs/winnow
Other
572 stars 44 forks source link

Any combinator function the if-else logic in this code appears to have no practical difference #404

Closed baoyachi closed 10 months ago

baoyachi commented 10 months ago

Please complete the following tasks

winnow version

0.5.30

Describe your use case

The if-else logic in this code appears to have no practical difference. In both the if and else branches, the any::<, _, true>(input) function is called. Consequently, the if-else logic might be redundant.

https://github.com/winnow-rs/winnow/blob/02561943e396aab9fc268ec00c88273e3315ef0a/src/token/mod.rs#L46-L59

pub fn any<I, E: ParserError<I>>(input: &mut I) -> PResult<<I as Stream>::Token, E>
where
    I: StreamIsPartial,
    I: Stream,
{
    trace("any", move |input: &mut I| {
        if <I as StreamIsPartial>::is_partial_supported() {
+            any_::<_, _, true>(input)
+        } else {
+            any_::<_, _, true>(input)
        }
    })
    .parse_next(input)
}

Describe the solution you'd like

The if-else logic might be redundant and can be simplified by directly calling any_::<_, _, true>(input).

Alternatives, if applicable

No response

Additional Context

No response