-
Notifications
You must be signed in to change notification settings - Fork 805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support custom containers for many
functions
#1409
Comments
I guess this can be link to #1393. I think we can use https://doc.rust-lang.org/std/iter/trait.Extend.html to allow this for many.
You can add your own parser for reuse in the waiting, something like that (I'm more used to nom 6 so probably mistake): fn many0_string(f: impl Parser) -> impl Parser {
|input| {
fold_many0(
f,
String::new,
|mut acc: String, item| {
string.push_str(item);
acc
}
)(input)
}
}
What is combine ? I don't follow here.
Some sort of |
Sorry, e.g. https://docs.rs/combine/4.6.1/combine/fn.many.html has the collection set to
More like So speaking of, maybe we should have |
I think we can clearly add a |
Oh, thanks for looking to include I've split out |
oh, using Extend is a great suggestion! I was wondering about doing that too |
Prerequisites
Here are a few things you should provide to help me understand the issue:
Test case
I wanted to experiment with porting
toml_edit
to nom, one thing I especially found missing was custom collection support. If I usemany0
, it only supportsVec
. The naive approach in code is to doLeading me to allocate a
Vec<String>
and then merge them.combine
defaults toVec
but allows anyExtend
type, allowingwhich will collect directly into the
String
, saving on a lot of allocationsI'm also looking at optimizing a section of my parser where collect into a
Vec
and then turn it into aHashMap
with errors by creating a custom type that wrapsHashMap
with my error type and stores off errors onExtend
, allowing me to bypass theVec
allocation.I could do all of this with
fold_
variants but it will be a bit messier.The text was updated successfully, but these errors were encountered: