Skip to content
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

make many extend into other collections that Vec #1621

Merged
merged 9 commits into from
Jan 17, 2023
Merged

Conversation

Geal
Copy link
Collaborator

@Geal Geal commented Jan 15, 2023

Fix #1409

This will likely remove the optimizatio of preallocating vector capacity, but we can get this back with a wrapper type if needed, and being able to created directly a hashmap or other collections instead of going through a vec first will be way more useful

@coveralls
Copy link

coveralls commented Jan 15, 2023

Pull Request Test Coverage Report for Build 3925742307

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 15 of 15 (100.0%) changed or added relevant lines in 1 file are covered.
  • 9 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.3%) to 62.144%

Files with Coverage Reduction New Missed Lines %
src/multi/mod.rs 1 90.54%
src/traits.rs 8 62.79%
Totals Coverage Status
Change from base Build 3924923584: -0.3%
Covered Lines: 1548
Relevant Lines: 2491

💛 - Coveralls

@@ -491,7 +491,7 @@ mod test {
let b = "ababcd";

fn f(i: &str) -> IResult<&str, &str> {
recognize(many(1.., alt((tag("a"), tag("b")))))(i)
recognize::<_, Vec<&str>, _, _>(many(1.., alt((tag("a"), tag("b")))))(i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been going back and forth on this idea partly because of type inference issues when fold_many* easily let's people do the same thing. I was surprised; they came up less than I expected.

This will likely remove the optimizatio of preallocating vector capacity, but we can get this back with a wrapper type if needed, and being able to created directly a hashmap or other collections instead of going through a vec first will be way more useful

fold_many is likely lighter weight than a newtype (code wise). Maybe we should provide a fold_many example that sets the capacity and have many link out to it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense that there would be inference issues in the tests calling many directly and the ones using recognize , but it worked surprisingly well everywhere else, so this is giving me confidence to make this change.

The example pointing towards fold_many is a good idea, that will let people define their own capacity allocation

@Geal Geal marked this pull request as ready for review January 17, 2023 22:39
@Geal Geal merged commit 103f32f into main Jan 17, 2023
@Geal Geal deleted the extend-collection branch January 17, 2023 22:39
opt(multispace),
map(
many(0.., terminated(key_value, opt(multispace))),
|vec: Vec<_>| vec.into_iter().collect(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come this into_iter().collect() was left in?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed it, fixed in 4c6e45e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support custom containers for many functions
3 participants