-
I'm trying to migrate pkgcraft to Currently I'm fiddling dependency groups. At the bottom, there is a group parser: /// Capture one or more `parser`'s inside `()`, with spaces/newlines in between.
fn group<I, O, E>(parser: impl Parser<I, O, E>) -> impl Parser<I, Vec<O>, E>
where
I: StreamIsPartial + Stream + Compare<char>,
<I as Stream>::Token: AsChar + Clone,
E: ParserError<I>,
{
delimited(('(', multispace1), repeat(1.., terminated(parser, multispace1)), ')')
} There are multiple of these types of groups, one parser looks like this: /// The `any_of` group is preceded by '|| ' and denotes that any of the groups packages is sufficient.
fn any_of<I, E, O>(
parser: impl Parser<I, Dependency<O>, E>,
) -> impl FnMut(&mut I) -> Result<Dependency<O>, E>
where
I: StreamIsPartial + Stream + Compare<char>,
<I as Stream>::Token: AsChar + Clone,
O: Ordered,
E: ParserError<I>,
{
move |input: &mut I| {
let _ = ('|', '|', multispace1).parse_next(input)?;
let dependency_group = group(parser).parse_next(input)?;
Ok(Dependency::AnyOf(dependency_group.into_iter().map(Box::new).collect()))
}
} My first question is about the trait bounds: Is it right to always add more trait bounds (for let _ = ("||", multispace1).parse_next(input)?; I would have to add The second question is about the body of the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If you don't have to be generic, don't. When you need to be generic, yes, you need to add each bound. We tried to consolidate as many traits as possible to reduce this but there is only so much that can be done. You can see winnow doing this in parsers like
You'll want to use |
Beta Was this translation helpful? Give feedback.
If you don't have to be generic, don't.
When you need to be generic, yes, you need to add each bound. We tried to consolidate as many traits as possible to reduce this but there is only so much that can be done. You can see winnow doing this in parsers like
float