winnow-rs / winnow

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

use any combinator build error when Input receiver BStr #546

Closed baoyachi closed 3 months ago

baoyachi commented 3 months ago

Please complete the following tasks

rust version

rustc 1.78.0 (9b00956e5 2024-04-29)

winnow version

0.6.13

Minimal reproducible code

use winnow::{BStr, Parser, PResult};
use winnow::token::{any};

fn main() {
}

fn char_token(input:&mut BStr) -> PResult<char>{
    any.try_map(char::try_from).parse_next(input)
}

Steps to reproduce the bug with the above code

cargo run

Actual Behaviour

error[E0277]: the trait bound `BStr: StreamIsPartial` is not satisfied
  --> src/main.rs:7:5
   |
7  |     any.try_map(char::try_from).parse_next(input)
   |     ^^^ the trait `StreamIsPartial` is not implemented for `BStr`
   |
   = help: the trait `StreamIsPartial` is implemented for `&'a BStr`
note: required by a bound in `winnow::token::any`
  --> /Users/baoyachi/.cargo/registry/src/winnow-0.6.8/src/token/mod.rs:60:12
   |
58 | pub fn any<Input, Error>(input: &mut Input) -> PResult<<Input as Stream>::Token, Error>
   |        --- required by a bound in this function
59 | where
60 |     Input: StreamIsPartial + Stream,
   |            ^^^^^^^^^^^^^^^ required by this bound in `any`

Expected Behaviour

how to use any combinator get char

Additional Context

No response

baoyachi commented 3 months ago

But use Located<&winnow::BStr> is ok, it's surprised

use winnow::{BStr, Located, Parser, PResult};
use winnow::token::{any};

fn main() {}

fn char_token(input: &mut Located<&winnow::BStr>) -> PResult<char> {
    any.try_map(char::try_from).parse_next(input)
}
epage commented 3 months ago

Try

use winnow::{BStr, Parser, PResult};
use winnow::token::{any};

fn main() {
}

-fn char_token(input:&mut BStr) -> PResult<char>{
+fn char_token(input:&mut &BStr) -> PResult<char>{
    any.try_map(char::try_from).parse_next(input)
}
baoyachi commented 3 months ago

Thx @epage .I overlooked the details.