rust-bakery / nom

Rust parser combinator framework
MIT License
9.38k stars 806 forks source link

Make traits public #1644

Open jayhale opened 1 year ago

jayhale commented 1 year ago

nom::traits is private. In order to implement generic parsers, it would be helpful to have access to the type defs.

Or there is another way that I don't know?

Prerequisites

Here are a few things you should provide to help me understand the issue:

Test case

Example test case: Offset and Slice are part of nom's private traits module.

// I want to implement a similar parser to `recognize` that sends back the consumed input and the results
pub fn recognize_children<I: Clone + Offset + Slice<RangeTo<usize>>, O, E: ParseError<I>, F>(
    mut parser: F,
  ) -> impl FnMut(I) -> IResult<I, (I, O), E>
  where
    F: Parser<I, O, E>,
  {
    move |input: I| {
      let i = input.clone();
      match parser.parse(i) {
        Ok((i, o)) => {
          let index = input.offset(&i);
          Ok((i, (input.slice(..index), o)))
        }
        Err(e) => Err(e),
      }
    }
  }
Geal commented 1 year ago

all the traits are exported at the root level: https://github.com/rust-bakery/nom/blob/main/src/lib.rs#L440